在我的spring批处理项目中,我需要从表中的行列表中读取,创建一个4的块并处理然后写入另一个表。我已经实现了SimpleAsyncTaskExecutor以允许并行处理块,但我发现在处理了记录集中的所有记录之后,Spring Batch正在尝试继续读取下一批结果并失败。超过跳过水平后,它显然会中止该工作。
我的查询是 - 为什么批处理在完成处理集合中的所有记录后继续寻找下一条记录?
我最后得到的错误是:
org.springframework.batch.core.step.item.FaultTolerantChunkProvider - 跳过失败的输入 org.springframework.jdbc.UncategorizedSQLException:尝试处理 下一行失败;未分类SQL的SQLException
以下是我的批量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>
答案 0 :(得分:1)
使用JdbcPagingItemReader解决了该问题。该阅读器将同步读取并且还需要按特定列排序数据。