Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 401
One Two Three Avatar asked Apr 08 '13 20:04

One Two Three


People also ask

What is core pool size?

Generally, any implementation of BlockingQueue in Java can be used as a work queue. Core Pool Size. The core pool size is the number of threads that should be alive in a thread pool. The core threads are not terminated by the thread pool even if they are idle.

What is core pool and max pool size?

The default configuration of core pool size is 1, max pool size and queue capacity as 2147483647. This is roughly equivalent to Executors.

What is maximum pool size in Java?

To set the maximum pool size: n is the number of connections allowed per pool, from 1 to 2,147,483,647 (the default).


1 Answers

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.

like image 178
Antoniossss Avatar answered Sep 28 '22 16:09

Antoniossss