Spring batch corePoolSize VS throttle-limit

13,706

Solution 1

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.

Solution 2

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.

Share:
13,706
Sinda MOKADDEM
Author by

Sinda MOKADDEM

Updated on July 18, 2022

Comments

  • Sinda MOKADDEM
    Sinda MOKADDEM almost 2 years

    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...

  • Sinda MOKADDEM
    Sinda MOKADDEM about 8 years
    Thank you for this clarification John, but what if the throttle-limit exceeds the corePoolSize ? for example Throttle-limit = 200 and CorePoolSize = 100 ? will the JVM crash ?
  • jezg1993
    jezg1993 about 8 years
    I don't know the implementation, but my best guess is that there a semaphore to throttle and excess submissions to the thread pool will simply cause those submissions to be queued up and executed at some point in the future.