How to set up multi-threading in Spring Batch?

巧了我就是萌 提交于 2019-11-27 13:18:17

Create a Split and you will be able to use multithreading between the different branches. Use a TaskExecutor to define your parallelism policy.

See Multi-threaded Step

Be sure to use the latest version of Spring Batch if you want to use multithreading and the MapJobRepository (prior to latest version, this JobRepository was not thread safe).

Take a look at Jean answers'. An easy way is create a bean of SimpleAsyncTaskExecutor and associate a tasklet to use this bean, like that.

<bean id="simpleTaskExecutor"
    class="org.springframework.core.task.SimpleAsyncTaskExecutor">
    <property name="concurrencyLimit" value="10"/>
</bean>

<batch:job id="jobTest">
    <batch:step id="step1">
    <!-- throttle-limit default is 4. Increase this to ensure that a thread pool is fully utilized -->
        <batch:tasklet task-executor="simpleTaskExecutor" throttle-limit="20">
            <batch:chunk />
        </batch:tasklet>
    </batch:step>
</batch:job>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!