how to run a java program from another java program independently?
I am running the code below. this runs the two instances of validity.jar as threads and main is not completed. I want to complete the ma开发者_运维知识库in methods execution with out waiting for the completion of validity.jar. How can i do this?
try
{
int counter = 0;
while(counter <2)
{
counter++;
java.lang.Runtime.getRuntime().exec("java -jar C:\\validity.jar");
}
} // try
catch(Exception e)
{
e.printStackTrace();
} // catch
Couldn't you add the jar file to the build-path of your project?
Then make a Thread
or Runnable
of your main
class and start that twice?
public class SomeThread extends Thread {
@Override
public void run(){
try {
System.out.println("Starting thread");
SomeThread.sleep(10000);
System.out.println("Done thread!");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("Start of main");
Thread t = new SomeThread();
t.start();
System.out.println("Finished main");
}
}
精彩评论