我在Spring Batch的一個新手。我有繼承了一個使用Spring Batch實現的批處理。 這個效果很好,除了我會嘗試描述的一件事。Spring Batch的:一直在尋找的文件與MultiResourceItemReader
我啓動parseJob和,當它讀取XML在豆parsingStepReader處理, read()方法時被調用始終。
目錄* path_to_xml *只包含一個XML,調用read()並返回解析的XML,處理OK。然後,再次調用read()方法,返回一個空對象,然後再次調用,返回null ...等等。
調試時,MultiResourceItemReader 讀取方法嘗試讀取,不讀取任何東西(所有資源已經被讀取),遞增currentResources並返回null。
我已經readed你對這項工作停止時,讀寫器返回一個空的對象,但閱讀方法返回null,再而三讀... 我改變了重新啓動的假,但不起作用。
的工作在Linux中,批處理模式推出,與由於這一問題org.springframework.batch.core.launch.support.CommandLineJobRunner ,即啓動作業沒有完成.SH和資源都很忙。
我怎樣才能避免這種情況,或者當資源(XML)輸入目錄已經處理停止作業? 任何幫助將不勝感激。最好的祝福。
豆類文件和Java類件連接
<batch:job id="parseJob" restartable="true" incrementer="jobParametersIncrementer">
<batch:flow parent="parseFlow"/>
<batch:flow .../>
<batch:flow .../>
</batch:job>
<batch:flow id="parseFlow">
<batch:step id="parsingStep">
<batch:tasklet start-limit="100" allow-start-if-complete="true" transaction-manager="..." task-executor="taskExecutor" throttle-limit="$...">
<batch:chunk reader="parsingStepReader" writer="..." processor="..." commit-interval="..." skip-limit="10000000">
<batch:skippable-exception-classes>
<batch:include class="java.lang.Exception" />
</batch:skippable-exception-classes>
</batch:chunk>
<batch:listeners>
<batch:listener ref="iwListener" />
<batch:listener ref="mySkipListener" />
<batch:listener ref="myStep1Listener" />
</batch:listeners>
<batch:no-rollback-exception-classes>
<batch:include class="java.lang.Exception" />
</batch:no-rollback-exception-classes>
</batch:tasklet>
</batch:step>
</batch:flow>
<!-- -->
<bean id="bpfReader" class="org.springframework.batch.item.xml.StaxEventItemReader" scope="prototype">
<property name="fragmentRootElementName" value="..." />
<property name="unmarshaller" ref="..." />
<property name="strict" value="false" />
</bean>
<bean id="multiresourceItemReader" class="...SyncMultiResourceItemReader" abstract="true">
<property name="strict" value="false" />
<property name="delegate" ref="bpfReader" />
</bean>
<bean id="parsingStepReader" parent="multiresourceItemReader" scope="step">
<property name="resources" value="<path_to_xml>" />
</bean>
和閱讀器類:
public class SyncMultiResourceItemReader<T> extends MultiResourceItemReader<T> {
. . .
@Override
public T read() throws Exception, UnexpectedInputException, ParseException {
synchronized (this) {
return super.read();
}
}
. . .
}
UPDATE:解決方案通過@vsingh提出完美的作品。一旦選擇輸入元素,它必須從輸入中刪除。我不知道爲什麼,但類org.springframework.batch.item.file.MultiResourceItemReader不能正常工作,特別是在輸入錯誤。
我希望這會有所幫助。此致敬意
你能更準確的問題:'MultiResourceItemReader#read()'返回null,因爲輸入資源被鎖定?或者Spring Batch繼續調用'read()'方法,儘管它剛剛返回'null'? – 2012-04-07 22:31:25
@dma_k,當你闡明問題時,錯誤的問題是你的第二種方式,所以'read()'返回null,並且被一次又一次地調用。我認爲解決方案就像[this](http://stackoverflow.com/questions/7781012/spring-batch-stax-xml-reading-job-is-not-ending-when-out-of-input/10009614 #10009614),但目前還不清楚。謝謝@dma_k – 2012-04-09 05:09:29