Java Scheduled Executor:如果任务尚未完成,它是否保证不并行运行

StackOverflow https://stackoverflow.com/questions/1632371

  •  06-07-2019
  •  | 
  •  

有没有人知道java.util.concurrent包中的以下java方法 ScheduledExecutorService.html#scheduleAtFixedRate()

绝对保证,如果来自“最后”的可运行的话,Runnable预定将永远不会并行运行。跑还没完呢:

例如(Pseudocode)

1.00 o'clock: scheduleAtFixedRate(MyRunnable, "Run ever Hour")`
//1.30 o'clock: MyRunnable Has finished (everthing is fine)
2.00 o'clock: MyRunnable is triggered to run again
3.00 o'clock: MyRunnable has NOT yet finished ==> What will happen here? 
Will java Simply SKIP the starting of MyRunnable (as the old instance has not yet 
finished) and try again at 4 o'clock or will Java start a NEW MyRunnable that then will 
run in parallel to the "old" MyRunnable.

非常感谢你 Jan

有帮助吗?

解决方案

来自 docs

  

如果执行此任务,则执行此操作   那么比它的时期更长   随后的处决可能会迟到,   但不会同时执行。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top