![](/img/trans.png)
[英]Tables are getting refreshed after re-executing the application with EmbeddedDatabaseBuilder using derby
[英]Re-executing a Java program after a certain delay
我希望在Eclipse中多次執行Java程序並且有一定的延遲。 我試圖使用ScheduleAtFixedRate()
在一段時間后重新執行該程序。 那么ScheduleAtFixedRate()
和ScheduledExecutorService
之間的主要區別是什么?
使用后者有什么好處? 當計算機設置為睡眠模式時,它是否繼續運行執行計划?
如果你的意思是.scheduleAtFixedRate()
(請注意小s
),那么它是ScheduledExecutorService
提供的方法 。 因此,使用任何一種都沒有{dis,}優勢。
您可以通過調用創建ScheduledExecutorService
,例如:
final ScheduledExecutorService service
= Executors.newScheduledThreadPool(...);
service.scheduleAtFixedRate(...);
至於:
當計算機設置為睡眠模式時,它是否繼續運行執行計划?
不是。操作系統讓計算機進入睡眠狀態,操作系統應該指示您在所需的時間喚醒。 運行Java程序是JVM的一個過程,最終由OS控制。
ScheduledExecutorService是定義任務執行程序行為的接口,ScheduleAtFixedRate()是此接口的方法,它期望實現類即執行程序以固定間隔執行輸入任務。
當您的計算機進入睡眠狀態或休眠狀態時,將執行任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.