Jun 27th, 2008, 03:58 AM
Strange things with Tasklet and stepListeners
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.
Jun 27th, 2008, 09:00 AM
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.
Jun 27th, 2008, 09:39 AM
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.
Jun 27th, 2008, 10:25 AM
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
Jun 27th, 2008, 10:38 AM
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.
Jun 27th, 2008, 11:56 AM
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.
Jun 27th, 2008, 02:00 PM
Hmm... I see.
I'll look for some errors or mistakes.
Thank you for your help.
Tags for this Thread