Results 1 to 4 of 4

Thread: How to run the step just once

  1. #1
    Join Date
    May 2010
    Posts
    11

    Default How to run the step just once

    I have a requirement to run the reader-> processor -> writer iteration just once in my step. My understanding is that these iterations continue as long as the reader continues to return the data. Is it possible to run the iteration just once.

    I am using a taskletstep and a chunk configured inside it. Is there an alternative for it or do we need to take care programatically?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    You could provide a chunk completion policy to the chunk which completes the chunk after a single read.

  3. #3
    Join Date
    May 2010
    Posts
    11

    Default

    I tried using SimpleCompletionPolicy with the chunk size set to 1. The resultant behaviour is similar to setting the commit-interval to 1. The writer write method is getting invoked after every call to read method of the reader. But my requirement is that the step should get completed after 1 read and 1 write.

    Below is the xml configuration I am using:

    <job id="publishJob" xmlns="http://www.springframework.org/schema/batch">
    <step id="fileWriteStep.master">
    <partition step="fileWriteStep" partitioner="fileNamePartitioner">
    <handler grid-size="2" task-executor="asyncTaskExecutor"/>
    </partition>
    </step>
    </job>


    <step id="fileWriteStep" xmlns="http://www.springframework.org/schema/batch">
    <tasklet>
    <chunk reader="fileReader" processor="fileXMLProcessor" writer="fileWriter"
    chunk-completion-policy="simpleCompletionPolicy" />
    </tasklet>
    </step>

    <bean id="simpleCompletionPolicy" class="org.springframework.batch.repeat.policy.Sim pleCompletionPolicy">
    <property name="chunkSize" value="2">
    </bean>

    Please let me know if I am doing something wrong.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    I see. That's the wrong completion policy. Try a *StepFactoryBean as a parent to your step with stepOperations (not chunkOperations) set to the simpleCompletionPolicy.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •