Simply_me
Simply_me

Reputation: 2970

Converting From ScheduleAtFixedRate To CachedThreadPool

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

Answers (1)

jtahlborn
jtahlborn

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

Related Questions