我正在运行下面的代码。这将validation.jar 的两个实例作为线程运行,并且main 未完成。我想完成主要方法的执行而不等待validation.jar 的完成。我怎样才能做到这一点?
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
最佳答案
您不能将 jar 文件添加到项目的构建路径中吗?
然后为您的main
类创建一个Thread
或Runnable
并启动两次?
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");
}
}
关于java - 如何独立运行一个java程序和另一个java程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6760092/