Results 1 to 7 of 7

Thread: Strange things with Tasklet and stepListeners

  1. #1
    Join Date
    Jun 2008
    Posts
    4

    Default Strange things with Tasklet and stepListeners

    Hello,

    I currently use Spring Batch for a customer and I encounter a little problem with Tasklet.
    I have a job that execute two steps. A simple ItemOrientedStep which register some steplisteners, and a Tasklet (in this case, for send an email to the customer when the file is treat) which implement itself StepExecutionListener.

    My problem here is that the Tasklet don't register only itself for steplistening, but all the others too.

    What is the good thing to do? Can we configure the job/step/tasklet to stop the auto-registration? (And use the deprecated setStepListeners instead).
    Or the Tasklet is maybe not the right solution and the better is to use another stepListener for send my email (with onErrorInStep and afterStep)

    In brief, help

    Thank you a lot if you have read this post until the end. I know my English is bad.

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    The Tasklet should definitely only be used as part of a TaskletStep. I.e., as a separate step. I'm not sure I fully understand what you're doing, but it sounds like you've somehow used a Tasklet as a StepListener. I think you're guess is correct, that you should just use a StepListener.

  3. #3
    Join Date
    Jun 2008
    Posts
    4

    Default

    I Just want to access the context (stepExecution, for access some job states) of my Tasklet which is only use as a separated step.

    Indeed, it's exactly what I want. That my step (Tasklet) hasn't any relation with the first step (ItemOriented), then, any other steplisteners except itself.

    Like you say, maybe the better solution is to do a simple steplistener and only one step. But the Tasklet is perfect for this work, send an email even the precedent step failed.

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I understand the problem a little bit better now. You want to access some state from the first step in the second step. In 1.0.1, this is a bit tricky. The workaround is to have a StepListener for both steps that copies values from one StepExecution to another.

    This issue has been fixed in 1.1, with the addition of a Job level ExecutionContext, but the above is a workaround for 1.0.x

  5. #5
    Join Date
    Jun 2008
    Posts
    4

    Default

    In first, I want to thank you for your patience

    Then... The job level ExecutionContext, if it is accessible in a tasklet (for example ) will be perfect for communicate between steps.

    Till then, if I want to apply your 1.0.1 "trick". I've got the problem that my Tasklet register every stepListeners that it find in my configuration files (Not only itself indeed).

    As I'm new in Spring Batch, I just want to know if it's normal (And I just use a stepListener) or not.

    Thank you again.

    Kind regards

  6. #6
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    All StepListeners have to be manually registered to a TaskletStep, it doesn't auto register anything from an application context. There's probably some error in configuration.

  7. #7
    Join Date
    Jun 2008
    Posts
    4

    Default

    Hmm... I see.

    I'll look for some errors or mistakes.

    Thank you for your help.

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
  •