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
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.
The default configuration of core pool size is 1, max pool size and queue capacity as 2147483647. This is roughly equivalent to Executors.
To set the maximum pool size: n is the number of connections allowed per pool, from 1 to 2,147,483,647 (the default).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With