meaning of 'core pool size' in ScheduledThreadPoolExecutor's constructor

One Two Three picture One Two Three · Apr 8, 2013 · Viewed 7.8k times · Source

I'm new to ScheduledThreadPoolExecutor (as I usually use the simple Timer, but people have been advising against it), and I don't quite understand what would be the appropriate integer value to pass to the ScheduledThreadPoolExecutor(int) constructor.

Could anyone explain this?

Thank you

Answer

Antoniossss picture Antoniossss · Aug 19, 2016

In case of ScheduledThreadPoolExecutor, corePoolSize is maximum number of threads that will be created to perform scheduled actions. This thread pool is fixed-sized and idle threads are kept alive.

DrunkenRabbit's answer is simply ivalid because ScheduledThreadPoolsExecutor docs says explicitly that (There will be no thread count spikes at all):

While this class inherits from ThreadPoolExecutor, a few of the inherited tuning methods are not useful for it. In particular, because it acts as a fixed-sized pool using corePoolSize threads and an unbounded queue, adjustments to maximumPoolSize have no useful effect.

Now as for the value, reasonable number would be number of CPU cores that application is running on.