Results 1 to 3 of 3

Thread: step listeners triggered twice

  1. #1

    Thumbs down step listeners triggered twice

    This is more to share what our team has encountered in our testing using Spring Batch 'StepListeners' (2.0.1.RELEASE).

    If you happen to configure your step listeners the way as shown in the doc i.e. explicitly configured as part of the <step> and <tasklet>

    Code:
    <step id="step1">
        <tasklet>
            <chunk reader="reader" writer="writer" commit-interval="10"/>
            <listeners>
                <listener ref="stepListener"/>
            </listeners>
        </tasklet>
    </step>
    and then your listeners are implemented in the same class as the ItemReader, ItemProcessor or ItemWriter then you'll encounter duplicate invocations of the StepListener methods.

    At first we thought there's something wrong in our implementation, context loading, job invocation, logging, etc until we suspected that probably the listeners were being registered twice and that's probably causing the duplicate runs. True enough, if your StepListeners are in the same class as the ItemReader, ItemProcessor or ItemWriter they are automatically registered! So explicitly configuring it again in the <step> config make them to be registered twice and thus invoked twice.

    Well it is documented here and we missed it. http://static.springsource.org/sprin...gStepExecution

    How did this happen? Initially our StepListener implementations are in a separate class so the above configuration worked. Later we decided to merge it with the Item listener implementations and changing only the class/bean in the <listener> configuration. Who would have thought we are now registering the step listeners twice?

    Spring Batch should probably be more intelligent to detect duplicate listeners being registered twice. It's good that it can register StepListeners automatically but might as well not do it if it cannot detect manual registration that will cause duplicates.
    Last edited by adrian; Jan 26th, 2010 at 07:37 PM.

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

    Default

    You could always raise an issue in JIRA for the duplicate detection.

  3. #3

    Default

    Thanks, Dave. I would assume the issue still holds true on newer releases. JIRA has been raised. http://jira.springframework.org/browse/BATCH-1493

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
  •