【发布时间】:2017-03-01 07:28:53
【问题描述】:
我在 java 中编写了一个脚本,使用它执行 .exe 文件来安装应用程序,之后我将通过安装生成的文件复制到远程位置。但问题是在安装完成之前,将文件复制到机器位置的下一步正在发生。因此导致粘贴空文件,因为安装没有完成,所以文件在那里。我怎样才能停止我的过程,直到上一步结束。我尝试使用 thread.sleep(10000) 但这无济于事,因为安装时间可能会有所不同。
public class threadJoin {
public static void main(String s[]){
Runnable r = new Runnable() {
@Override
public void run() {
File f = new File("C:\\D\\EVProject\\");
FilenameFilter textFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("EVProject");
}
};
File[] files = f.listFiles(textFilter);
for (File file : files) {
try {
String filexy = file.getCanonicalPath();
System.out.print(filexy);
Runtime.getRuntime().exec(filexy);
//Thread.sleep(10000);
} catch (IOException ex) {
Logger.getLogger(threadJoin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
String l ="C:\\Program Files\\PD ";
String m = "C:\\0.0.9.8";
File srcDir = new File(l);
File destDir = new File(m);
try {
FileUtils.copyDirectory(srcDir, destDir);
} catch (IOException e) {
}
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
Thread t1= new Thread(r);
Thread t2 = new Thread(r2);
t1.start();
try{
t1.join();
}catch(InterruptedException e){
}
t2.start();
}
}
【问题讨论】:
-
你能显示代码吗?
-
你的程序怎么知道安装完成了?
-
它不检查安装是否完成。我的程序只是调用 .exe 文件@DanielWiddis
标签: java multithreading join installation