This post is part of a series delving into the details of the JSR-352 (Java Batch) specification. Each post examines a very specific part of the specification and looks at how it works and how you might use it in a real batch application.
To start at the beginning, follow the link to the first post.
The next post in the series is here.
A Decision element in the JSL is used to specify a Decider batch artifact which you can use to make decisions about what to do next.
A Decision element is kind of like a special type of step in the JSL. You can reference it as the next element from a step, a flow, or a split. It cannot be the first step in a job. The purpose of a Decision element is to give you a special point in the processing of a job where you can make decisions about what to do next. You might decide to branch this way instead of that, or to end the job (for good or bad) right here, or maybe something has gone horribly wrong and the job just needs to stop so it can be restarted after some issue is resolved.
Well, that’s all fine, but can’t you do all that with a normal step? Kind of.. A simple batchlet step will get control and can set a Step Exit Status that can be used with flow-control elements in the step to decide where to go next or to end the job.
A Decision has a few extras that make it special. The first special thing is that the implementation (a Decider) gets control in its decide method with an array of StepExecution objects as a parameter. A batchlet gets nothing (except injected properties).
A Decider also gets to return a string. A batchlet returns nothing. Why does it return a string? Because a Decider gets to set the Exit Status for the whole Job. That makes the Decider an interesting option as the final step in the job.
We still need to talk about what that StepExecution object is that the Decider gets as a parameter and why that would be an array…. Something for the next post…see you then!