J
JayJay1
Gast
Ziel ist es ein 2. Java Program parallel in einem Thread per Runtime.getruntime().exec zu starten. Problem ist jedoch dass der Prozess nicht unabhängig von Thread 1 nutzen kann......
Sieht jemand einen Fehler?
Sieht jemand einen Fehler?
Code:
public class Main {
public static void main( String[] args )
{
try{
String cmd = "java -cp myapp Main-Class";
Thread s = new Thread( new ServiceApp("Test-App", cmd), "1" );
s.start();
Thread.sleep(10000);
System.out.println("test");
//app.destroy();
}catch( Exception e ){
e.printStackTrace();
}
}
Code:
public class ServiceApp implements Runnable
{
private String sName = "";
private String sCommand = "";
private Process process = null;
public ServiceApp(String name, String cmd){
sName = name;
sCommand = cmd;
}
public ServiceApp(){
}
public void destroy(){
if( process != null )
process.destroy();
}
public void run(){
try{
process = Runtime.getRuntime().exec( sCommand );
process.waitFor();
System.out.println("Finished");
}catch( Exception e ){
e.printStackTrace();
}
}
}