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.
The JSR-352 specification includes a concurrency feature generally referred to as split/flows. We’ll look at how this allows for concurrency and more details of a split next time. For now, let’s just have a look at a flow.
What is a flow? It is basically just a group of execution elements wrapped in
Don’t be tempted to think of this is sort of a sub-routine that you can branch to whenever needed. The parts of a flow are still steps in the job and you can only execute a particular step once in the job. If you branch back to the same flow more than once the job will fail.
A flow can also have its own flow control (a ‘next’ tag in the ‘flow’ element) that indicates where in the JSL control should go once the flow is complete. There is no way to do conditional flow control based on the outcome of the entire flow with just JSL. We’ll talk later about how a decision element can be used for that.
Unless the flow is contained within a split, if there is no ‘next’ tag on the ‘flow’ then the job ends when the flow is complete, just like it does for a regular step with no indication of what to do next.
The steps within a flow can, of course, have all the usual control options, including passing control to other steps. But those target steps HAVE to be within the flow. The flow is a grouping of execution elements and any branching around between them has to happen entirely within the flow. Attempts to branch out of the flow will result in the job failing.
Finally, I’ve been careful to say that a flow contains “execution elements” and not just “steps”. That’s because a flow can contain any executable element, including steps, other flows nested inside this one, or splits (containing other flows). You can make quite a complicated mess. If you do, be careful to understand the scoping because a step inside a flow inside a flow can’t branch outside the inner flow. Got that?
All that said, a flow isn’t all that exciting until we get to the split. That’s up next.