Spring batch corePoolSize VS throttle-limit

穿精又带淫゛_ 提交于 2019-12-03 04:41:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!