How to prevent the parallel execution of a Step used in two Jobs in JBeret?

166 Views Asked by At

I am using JBeret on Wildfly, lets say I have Job1 that consists of StepA, StepB, StepC. Lets say I have Job2 that consists of StepB.

Now, when both Jobs run at the same time, I would like to prevent StepB to be executed in prallel. Meaning Job1 should wait or fail if Job2 runs StepB while Job1 wants to start StepB.

How can I achieve this?

Thank you.

1

There are 1 best solutions below

0
cheng On

You can use a singleton bean that holds a flag, e.g., AtomicBoolean, CountDownLatch. Before starting stepB, in its associated step listener, try to query and update the flag, and if successful, then continue to run the step. Else, fail the step, or wait for certain duration and check again.

At the end of stepB execution, its step listener does the similar to release the lock.