gpt4 book ai didi

java - SimpleAsyncTaskExecutor 尝试在处理完成后读取记录

转载 作者:太空宇宙 更新时间:2023-11-04 07:44:12 25 4
gpt4 key购买 nike

在我的 Spring Batch 项目中,我需要从表中读取行列表,创建 4 行的 block 并进行处理,然后写入另一个表。我已经实现了 SimpleAsyncTaskExecutor 以允许并行处理 block ,但我发现在处理记录集中的所有记录后,Spring Batch 尝试继续读取下一批结果并失败。超过跳过级别后,显然会中止作业。

我的疑问是 - 为什么批处理在处理完集合中的所有记录后会继续寻找下一条记录?

我最后得到的错误是:

org.springframework.batch.core.step.item.FaultTolerantChunkProvider - Skipping failed input org.springframework.jdbc.UncategorizedSQLException: Attempt to process next row failed; uncategorized SQLException for SQL

下面是我的批处理 xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<beans:import resource="../launch-context.xml" />

<beans:bean id="wsStudentItemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
<beans:property name="dataSource" ref="rptDS" />
<beans:property name="sql"
value="SELECT * FROM STUDENTS WHERE BATCH_ID=?" />
<beans:property name="preparedStatementSetter">
<beans:bean class="com.test.BatchDtSetter"
autowire="byName">
<beans:property name="batchId" value="#{jobParameters[batchId]}" />
</beans:bean>
</beans:property>
<beans:property name="rowMapper" ref="wsRowMapper" />
</beans:bean>


<beans:bean id="outputWriter"
class="org.springframework.batch.item.support.ClassifierCompositeItemWriter">
<beans:property name="classifier" ref="writerClassifier" >
</beans:property>
</beans:bean>

<beans:bean id="writerClassifier"
class="com.test.WriterClassifier">
<beans:property name="codeFailWriter" ref="failJdbcBatchItemWriter" />
<beans:property name="codePassWriter" ref="passJdbcBatchItemWriter"></beans:property>
</beans:bean>

<beans:bean id="failJdbcBatchItemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="rptDS" />
<beans:property name="sql"
value="DELETE FROM STUDENTS WHERE BATCH_ID=?" />
<beans:property name="itemPreparedStatementSetter" ref="FailStatusSetter" />
</beans:bean>

<beans:bean id="FailStatusSetter" class="com.test.FailStatusSetter" />

<beans:bean id="passJdbcBatchItemWriter"
class="com.test.PassBatchItemWriter">
</beans:bean>

<beans:bean id="WSListnr"
class="com.test.WSBatchListnr">
<beans:property name="dataSource" ref="rptDS" />
</beans:bean>


<beans:bean id="wsRowMapper" class="com.test.WSReqMapper" />
<beans:bean id="wsReqPrcsr"
class="com.test.WSReqProc">
<beans:property name="dataSource" ref="rptDS" />
</beans:bean>
<beans:bean id="wsReqPrepStmtSetter" class="com.test.wsStudentSetter" />

<step id="initiateStep">
<tasklet ref="initiateStepTask" />
</step>
<step id="wsStudentGenStep">
<tasklet task-executor="taskExecutor">
<chunk reader="wsStudentItemReader" processor="wsReqPrcsr"
writer="outputWriter" commit-interval="4" skip-limit="20">
<skippable-exception-classes>
<include class="java.lang.Exception" />
</skippable-exception-classes>
</chunk>
<listeners>
<listener ref="WSListnr" />
</listeners>
</tasklet>
</step>
<job id="wsStudent">
<step id="wsStudentFileGenIntialStep" parent="initiateStep"
next="wsStudentFileGenStep" />
<step id="wsStudentFileGenStep" parent="wsStudentGenStep" />
</job>


<beans:bean id="initiateStepTask" class="com.test.Initializer"
scope="step">
</beans:bean>

<beans:bean id="taskExecutor"
class="org.springframework.core.task.SimpleAsyncTaskExecutor">
<beans:property name="concurrencyLimit" value="2"/>
</beans:bean>

</beans:beans>

最佳答案

该问题已通过使用 JdbcPagingItemReader 解决。该读取器将同步读取,并且还要求数据按特定列排序。

关于java - SimpleAsyncTaskExecutor 尝试在处理完成后读取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15587166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com