Announcement Announcement Module
Collapse
No announcement yet.
Spring Batch Job seems to be starting one step before next one finishes? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Batch Job seems to be starting one step before next one finishes?

    Hi all,

    I am new to Spring Batch and hope someone can help me.

    I have a simple job with three steps. The first steps does something with a file using a tasklet and then writes it back with a different name/extenstion. Step 2 is a chunk related reader/writer step that picks up this file, reads it with a multiresourceitemreader (so that I could use wildcards) and writes it to a database. Step 3 renames this file.

    At first my job was implemented with step 2 only - works great. I then added the rename step - works fine. Then lastly I added step one...this is where the trouble starts. Step 1 on its own works...I can see the file being written back with the different extention. But step 2 now gives me a warning that there is no resources to be read. If then I comment out my tasklet code for step 1 (so the changed filename is still in the folder) and run the job again...then it does pick it up. So it almost seems as if Step 2 tries to find the file before it is written? Is this possible? Am I understanding batch correctly that one step has to complete before the next one start (in the way I wired it up?) Any ideas of what I can try to solve this?

    Some code samples below.

    Thanks

    JOB:
    Code:
    <job id="SpringJobBean.RPDataJob" job-repository="jobRepository">
            <!--incrementer="dynamicJobParameters">-->
            <step id="step1" next="step2">
                <tasklet ref="changeFileTasklet"/>
            </step>
            <step id="step2" next="step3">
                <tasklet transaction-manager="TransactionManager.DataExtracts">
                    <chunk reader="MultiResourceItemReader.RPDataJob"
                           writer="ItemWriter.RPDataJob"
                           commit-interval="1000"/>
                </tasklet>
            </step>
            <step id="step3">
                <tasklet ref="renameFilesTasklet"/>
            </step>
        </job>
    TASKLETS:
    Code:
        <beans:bean id="changeFileTasklet" class="com.ChangeFileTasklet">
            <beans:property name="filePathName" value="D:/DataExtractSampleFiles/"/>
        </beans:bean>
    
        <beans:bean id="renameFilesTasklet" class="com.RenameFilesTasklet">
            <beans:property name="fileName" value="_TEST.txt"/>
        </beans:bean>
    READER:
    Code:
        <beans:bean id="MultiResourceItemReader.RPDataJob" class="org.springframework.batch.item.file.MultiResourceItemReader">
            <beans:property name="resources" value="file:D:/DataExtractSampleFiles/*_TEST.txt"/>
            <beans:property name="delegate" ref="ItemReader.RPataJob">
            </beans:property>
        </beans:bean>
    Last edited by Zenoe; May 31st, 2012, 01:57 AM.
Working...
X