Reputation: 2970
The thread below runs every 12-24 hours, and I don't want to have an idle thread in the pool. The current code is:
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
...
scheduler.scheduleAtFixedRate(() -> getLastestJson(), INITIAL_DELAY, CHECK_INTERVAL, TimeUnit.MINUTES);
How can I leverage newCachedThreadPool()
in this case where CHECK_INTERVAL > 12hrs. The duration of the operation is < 15 sec.
Upvotes: 0
Views: 93
Reputation: 53694
You can't, really, because a thread needs to be waiting in order to start the new work at the appropriate time. Your current version is the minimal solution, with 1 "idle" thread.
Upvotes: 1