我有一个spring批处理应用程序,它从DB表中读取记录,并在writer类中进行REST API调用以获取要缓存的数据。但是我观察到并非线程池中的所有线程都在运行。他们只需要4-5批次运行,因为该应用需要5个小时才能拨打120K电话。以下是春季批处理上下文
任务执行者:
<bean id="myTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="20"/>
<property name="maxPoolSize" value="20"/>
</bean>
批处理作业:
<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:请注意,dataSource有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>
答案 0 :(得分:0)
您需要为工作设置限制。在您的情况下,即使您的线程池具有可用的空闲线程,弹出批次将仅使用4个线程,默认的限制限制为4.