Announcement Announcement Module
Collapse
No announcement yet.
AfterStep being called twice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AfterStep being called twice

    Hi,

    I have a job with two steps. The first step reads data from a table and creates a list of objects, and the second step writes these objects to a flat file.

    I have a class which implements the ItemReader and ItemWriter interfaces. This class is configured as the writer for step 1(jdbcItemreader is the itemreader), and reader for step2(flatfileitemwriter is the writer here).

    I configured an afterstep for step 1 which does some final logic and adds the object to a list. I am using an AfterStep annotation to achive this funcationality. My problem is that this afterStep is being called twice.

    Here is my configuration:
    Code:
    <job id="createFxRatesReconFeed" incrementer="runIncrementer">
    	<step id="loadFxRates" next="writeFxRates">
    		<tasklet>
    			<chunk reader="fxRatesReader" writer="fxRatesProcessor"
    				commit-interval="10" />
    			<listeners>
    				<listener ref="fxRatesProcessor" />
    			</listeners>
    		</tasklet>
    	</step>
    	<step id="writeFxRates">
    		<tasklet>
    			<chunk reader="fxRatesProcessor" writer="fxRatesWriter"
    				commit-interval="100" />
    		</tasklet>
    	</step>
    </job>
    My questions are:
    1. Why does my listener's after method gets called twice?
    2. The listener documentation states that I can use a pojo and specify the *-method in the configuration. So I expected something like this would work without using the AfterStep annotation or implementing the StepListener, but wrong again. The afterWrite method never got called.
    Code:
    <job id="createFxRatesReconFeed" incrementer="runIncrementer">
    	<step id="loadFxRates" next="writeFxRates">
    		<tasklet>
    			<chunk reader="fxRatesReader" writer="fxRatesProcessor"
    				commit-interval="10" />
    			<listeners>
    				<listener ref="fxRatesProcessor" after-step-method="afterWrite" />
    			</listeners>
    		</tasklet>
    	</step>
    	<step id="writeFxRates">
    		<tasklet>
    			<chunk reader="fxRatesProcessor" writer="fxRatesWriter"
    				commit-interval="100" />
    		</tasklet>
    	</step>
    </job>
    Thanks in advance.

  • #2
    BUMP Any help is appreciated.

    Comment


    • #3
      1. Why does my listener's after method gets called twice?

      From the documentation "An ItemReader, ItemWriter or ItemProcessor that itself implements one of the StepListener interfaces will be registered automatically with the Step..."

      Since fxRatesReader is being referenced in both steps it would be called twice - once at the end of each step.

      2. The listener documentation states that I can use a pojo and specify the *-method in the configuration. So I expected something like this would work without using the AfterStep annotation or implementing the StepListener, but wrong again. The afterWrite method never got called.

      Where does it say so? Could you point to the relevant part of the document?

      Comment


      • #4
        Thanks for the reply.
        Originally posted by SaifuddinMerchant View Post
        From the documentation "An ItemReader, ItemWriter or ItemProcessor that itself implements one of the StepListener interfaces will be registered automatically with the Step..."

        Since fxRatesReader is being referenced in both steps it would be called twice - once at the end of each step.
        I am not sure if that is the reason. I am configuring the listener in only one step, the first one.

        As for the documentation, i see that info when doing autocomplete in STS. I think its defined in the schema.

        Comment


        • #5
          Originally posted by zalym View Post
          I am not sure if that is the reason. I am configuring the listener in only one step, the first one.
          Even if you remove the configuration for listener from the first one, it would still be called.
          ItemReader, ItemWriter or ItemProcessor that are step listeners are auto registered.

          Comment

          Working...
          X