![](/img/trans.png)
[英]Catching Exceptions from (ExecutorService) CachedThreadPool
[英]Converting From ScheduleAtFixedRate To CachedThreadPool
下面的線程每12-24小時運行一次,我不想池中有一個空閑線程。 當前代碼是:
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
...
scheduler.scheduleAtFixedRate(() -> getLastestJson(), INITIAL_DELAY, CHECK_INTERVAL, TimeUnit.MINUTES);
在CHECK_INTERVAL> 12hrs的情況下,如何利用newCachedThreadPool()
。 操作時間<15秒。
確實不能,因為線程需要等待才能在適當的時間開始新工作。 當前版本是最小的解決方案,帶有1個“空閑”線程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.