1
在我的spring批處理項目中,我需要從表中讀取行的列表,創建一個4塊並處理,然後寫入另一個表。我已經實現了SimpleAsyncTaskExecutor以允許對塊進行並行處理,但是我發現在記錄集中的所有記錄都被處理後,Spring Batch正在嘗試繼續讀取下一批結果並失敗。超過跳過級別後,顯然會中止工作。SimpleAsyncTaskExecutor在處理完成後試圖讀取記錄
我的查詢是 - 爲什麼批處理會在處理集合中的所有記錄完成後繼續查找下一條記錄?
錯誤我在最後得到的是:
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>
使用** DefaultResultCompletionPolicy **,' ' –
jnivasreddy
2013-04-17 07:21:57
@jnivasreddy:behavious與使用commit-interval = 「4」或DefaultResultCompletionPolicy。 – 2013-05-07 17:11:36