i dont have clear what does it means the "corePoolSize" parameter of the newScheduledThreadPool() method from class java.util.concurrent.Executors.
What happen if i put a higher number value and what happen if i put a lower number value?
// corePoolSize = 1;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
or
// corePoolSize = 5;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
What is the correct way to define that value?
It is explained in details in the javadoc of ThreadPoolExecutor - extract:
When a new task is submitted in method
execute(Runnable)
, and fewer thancorePoolSize
threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more thancorePoolSize
but less thanmaximumPoolSize
threads running, a new thread will be created only if the queue is full.
So it defines if threads should be created or not depending on the state of the executor.
In the case of a ScheduledExecutorService
, if you don't plan to have more than one task running at a given time, a corePoolSize
of 1 is probably more efficient. And it won't prevent more threads to be created if required.
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