您好,我有一个方法,我想每 3 秒调用一次以进行一些计算,然后结果将继续使用一个新方法并在第一个方法停止时执行它的工作
Runnable helloRunnable = new Runnable() {
public void run() {
System.out.println("Hello world " + checkFileToReceive);
here is the calculation of the **intnumbOfChunks** which is used
in the main program
}
};
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(helloRunnable, 0, 3, TimeUnit.SECONDS);
在这里我让主程序做一些事情。在等待 helloRunnavle 完成时如何停止和启动主程序?主程序是
for (int i = 0; i < intnumbOfChunks; i++) {
fileToClaim = "";
fileToClaim = "bigbang.mp4";
fileToClaim = String.format("%s.part%06d", fileToClaim, i);
if (i==0){
checkFileToReceive = fileToClaim;
System.out.println("checkFileToReceive "+fileToClaim);
}
if (i%2==0){
fileparts.add(fileToClaim);
// System.out.println("fileToClaim "+fileToClaim);
}else {
fileparts1.add(fileToClaim);
// System.out.println("fileToClaim1 "+fileToClaim);
}
}