0
你好我有一个方法,我想打电话每3秒做一些计算,然后结果将继续一种新的方法,并做其工作,而第一种方法是停止如何在等待其他方法启动和停止每3秒停止一个java程序中的进程
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完成时停止并启动主程序? 主PROGRAMM是
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);
}
}
使用线程#加入 – Aurand
如何从线程传递intnumbOfChunks到主处理? – Cbour
在这个过程中我想测量两台服务器的速度。并计算后,看看有什么不妥,并把它放在列表中,以便知道我需要从每台服务器下载多少个区块以及我可以做多少个区块。但由于网络变化的速度,我需要每30秒计算一次速度!所以要改变列表! – Cbour