Java计划执行器服务等待所有线程完成 ScheduledExecutorService调度器=执行者。newScheduledThreadPool(4); 对于(int i=0;i

Java计划执行器服务等待所有线程完成 ScheduledExecutorService调度器=执行者。newScheduledThreadPool(4); 对于(int i=0;i,java,service,executor,Java,Service,Executor,到目前为止,以上是我的代码。但似乎永远也达不到顶点。。请帮忙,谢谢 而不是做 ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4); for (int i = 0; i < 4; i++) {Runnable autoUpdate = new autoUpdateWork(i); ScheduledFuture<?> scheduleAtFixedRate = scheduler.sch

到目前为止,以上是我的代码。但似乎永远也达不到顶点。。请帮忙,谢谢

而不是做

ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
for (int i = 0; i < 4; i++)
{Runnable autoUpdate = new autoUpdateWork(i);
ScheduledFuture<?> scheduleAtFixedRate = scheduler.scheduleAtFixedRate(autoUpdate, 0, 60, TimeUnit.SECONDS);
}
if (scheduleAtFixedRate != null)
    {    
        while(!scheduleAtFixedRate.isDone())
        //wait...
    }
//PointA :until all threads are finished, do sth, then invoke the scheduled task with 60 sec interval    again.
在您的Runnable类中添加一个如下所示的可变变量

if (scheduleAtFixedRate != null)
{    
    while(!scheduleAtFixedRate.isDone())
    //wait...
}
一旦你的线程完成了工作,把它改为true,然后在你的检查部分像这样放置

public  volatile boolean isRunning = false;

谢谢你的回复。我尝试了你的代码,但日程安排似乎立即全部终止?最后,我用另一个外部可运行类包装了可运行类。无论如何,谢谢你的帮助。
while(!autoUpdate.isRunning);