I'd like to know the difference between corePoolSize and throttle-limit as Spring Batch attributes defining multi threading configuration.
I've got the difference between corePoolSize and maxPoolSize thanks to this post "What is the difference between corePoolSize and maxPoolSize in the Spring ThreadPoolTaskExecutor"
But my issue concerns corePoolSize vs throttle-limit... I found that it's preferable to define CorePoolSize = Throttle-limit, but I'm wondering... if I define for example : CorePoolSize = 100 and Throttle-limit = 200... What happens ? Is a 200 sized thread pool that will be created or 100 ?
Thank you for any clarification...
The core pool size says a thread pool executor will start with N
number of threads. A throttle-limit T
says that, regardless of the number of threads available in the thread pool, only use T
of those threads for a tasklet.
So you can have a thread pool with a core pool size of 8 and two tasklets with throttle limit of 4 in that case you will be utilizing your thread pool. But if you only have one tasklet with a throttle limit of 4 you will be utilizing one half of the thread pool.
throttle-limit is explained in the spring batch javadocs in TaskExecutorRepeatTemplate.
This is another property on top of all the possible ways to configure a ThreadPoolExecutor and probably simplifies the task of using a thread pool. It's certainly useful if you have parallel steps competing for threads.
To answer your question, new threads will be created for your tasks if your throttle-limit is greater than corePoolSize
only if maximumPoolSize
is greater than corePoolSize
and the blocking queue in your ThreadPoolExecutor is full. Otherwise they will e.g. queue up in your ThreadPoolExecutor or possibly be rejected with an exception (see the default handler AbortPolicy).
What happens when spring batch tries to submit more tasks to the executor than it is willing to accept depends on your executor. See Rejected tasks in the ThreadPoolExecutor javadocs.
It's all a bit confusing at first, but makes perfect sense in the end.
Note that DEFAULT_THROTTLE_LIMIT
is 4 (in my spring version).
See for example this gotcha when your ThreadPoolExecutor is unexpectedly not creating any more than corePoolSize Threads.
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