Will a ScheduledExecutorService create new threads as needed?

Matt Ball picture Matt Ball · Jun 25, 2012 · Viewed 10.2k times · Source

I'm using Executors.newScheduledThreadPool() to create a ScheduledExecutorService, specifying the number of threads like so:

int corePoolSize = 42;
ScheduledExecutorService foo = Executors.newScheduledThreadPool(corePoolSize);

According to the JavaDocs, the corePoolSize argument sets

the number of threads to keep in the pool, even if they are idle.

Does this mean that this ExecutorService implementation may create more than corePoolSize threads as needed, similar to a cached thread pool?

Answer

Michael picture Michael · Jul 27, 2012

No. The correct answer is no, a ScheduledExecutorService will not spawn new threads.

See answer here