[英]Spring Batch : Not all threads are running from the threadpool
I have a spring batch application which reads records from DB table and makes REST API calls in the writer class to get the data to be cached. 我有一个spring批处理应用程序,该应用程序从数据库表中读取记录,并在writer类中进行REST API调用,以获取要缓存的数据。 However I observe that not all threads from the thread pool are running. 但是,我观察到并不是线程池中的所有线程都在运行。 They just run in the batches of 4-5 due which application takes 5 hours to make 120K calls. 它们仅以4-5的批次运行,因此应用程序需要5个小时才能拨打12万个电话。 Following is the spring batch context 以下是春季批处理上下文
Task Executor: 任务执行器:
<bean id="myTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="20"/>
<property name="maxPoolSize" value="20"/>
</bean>
Batch Job: 批处理作业:
<batch:job id="myBatchJob">
<batch:step id="loadData">
<batch:tasklet task-executor="myTaskExecutor"
transaction-manager="batchTransactionManager">
<batch:chunk reader="myReader" writer="myLoader"
commit-interval="250">
</batch:chunk>
<batch:listeners>
<batch:listener ref="batchStepListener" />
</batch:listeners>
</batch:tasklet>
</batch:step>
</batch:job>
Reader config: Note that the dataSource has 20 min/max connections 阅读器配置:请注意,数据源具有20个最小/最大连接
<batch:job id="myBatchJob">
<batch:step id="loadLei">
<batch:tasklet task-executor="myTaskExecutor"
transaction-manager="batchTransactionManager">
<batch:chunk reader="myReader" writer="myLoader"
commit-interval="250">
</batch:chunk>
<batch:listeners>
<batch:listener ref="batchStepListener" />
</batch:listeners>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="myReader"
class="org.springframework.batch.item.database.JdbcPagingItemReader">
<property name="dataSource" ref="myDataSource" />
<property name="queryProvider" ref="myQueryProvider" />
<property name="pageSize" value="1000" />
<property name="rowMapper" ref="myRowMapper" />
<property name="saveState" value="false" />
</bean>
<bean id="myQueryProvider"
class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="selectClause" value="SELECT * " />
<property name="fromClause" value="MYTABLE"/>
<property name="sortKeys">
<map>
<entry key="MYCOLUMN" value="ASCENDING"></entry>
</map>
</property>
</bean>
<bean id="myRowMapper"
class="com.my.RequestRowMapper">
</bean>
you need to set the throttle limit to your job. 您需要为您的工作设定油门极限。 The default throttle limit is 4. in your case even though your thread pool has free threads available the spring batch will use only 4 threads. 在您的情况下,默认限制为4。即使您的线程池有可用线程可用,spring批处理也将仅使用4个线程。
take a look at this Spring batch corePoolSize VS throttle-limit 看看这个Spring批处理corePoolSize VS节流阀极限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.