Package org.nuxeo.ecm.core.storage.sql
Class LockStepJob
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.sql.LockStepJob
-
- All Implemented Interfaces:
Runnable
public abstract class LockStepJob extends Object implements Runnable
Helper class to run jobs in lock step in several threads.You should override the
job()
method and make it execute code where blocks are wrapped in:if (thread(1)) { // code to execute only in thread 1 }
The parameter tothread(int)
should be 1, 2, 3... depending on the thread you want this block to be executed in.After you created the job instances, run the whole process by calling:
LockStepJob.run(job1, job2, job3...);
- Since:
- 5.7
-
-
Field Summary
Fields Modifier and Type Field Description protected CyclicBarrier
barrier
protected int
n
protected Throwable
throwable
-
Constructor Summary
Constructors Constructor Description LockStepJob()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
initialize(int n, CyclicBarrier barrier)
Run the thread n (1, 2...).abstract void
job()
Override this to define the actual job to execute in multiple threads.void
run()
static void
run(LockStepJob... jobs)
boolean
thread(int which)
Method to call around each part to be executed by a single thread.
-
-
-
Field Detail
-
n
protected int n
-
barrier
protected CyclicBarrier barrier
-
throwable
protected Throwable throwable
-
-
Method Detail
-
initialize
public void initialize(int n, CyclicBarrier barrier)
Run the thread n (1, 2...).
-
thread
public boolean thread(int which) throws Exception
Method to call around each part to be executed by a single thread.- Parameters:
which
- which thread is concerned- Returns:
true
if the code should be executed- Throws:
Exception
-
job
public abstract void job() throws Exception
Override this to define the actual job to execute in multiple threads.- Throws:
Exception
-
run
public static void run(LockStepJob... jobs) throws Exception
- Throws:
Exception
-
-