简体   繁体   English

Spring Batch:并非所有线程都在线程池中运行

[英]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.

相关问题 找出线程是否仍在threadPool中运行 - Find out if threads are still running in threadPool 如果发生异常,则停止ThreadPool中的所有线程 - Stoping all threads in ThreadPool if an exception occurs 春季:从Web App线程子线程(从ThreadPool)访问请求(会话)范围的Bean - Spring: Accessing Request (Session) Scoped Bean from Web App Thread Child Threads (from ThreadPool) 使用分区器的 Spring Batch 线程 - Spring Batch threads using partitioner 不执行无限制线程池执行程序中所有线程的原因是什么? - What is the reason of not executing all of the threads in an unbounded threadpool executer Java:运行Spring批处理 - Java: Running a Spring batch 线程池中线程之间的通信 - communication between threads in threadpool 如何停止悬吊线程池中的多个线程执行同一条语句? - How to stop multiple threads in the sling threadpool from executing the same statement? Spring Java:如何获得在线程池中运行的任务成功与失败的矩阵 - Spring Java: How to get a matrix for success, failure for a task running in a threadpool 提到超时的未来对象会为下一个线程不断增加(超时不适用于 Java 中 ThreadPool 中的所有线程) - Future Object with mentioned timeOut is keep increasing for the next threads(timeOut is not applying for all the threads in the ThreadPool in Java)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM