Thomas
Thomas

Reputation: 648

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

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.

Upvotes: 1

Views: 224

Answers (1)

cheng
cheng

Reputation: 1138

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.

Upvotes: 0

Related Questions