Package org.nuxeo.ecm.core.storage.sql
Class LockStepJob
java.lang.Object
org.nuxeo.ecm.core.storage.sql.LockStepJob
- All Implemented Interfaces:
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 to thread(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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinitialize(int n, CyclicBarrier barrier) Run the thread n (1, 2...).abstract voidjob()Override this to define the actual job to execute in multiple threads.voidrun()static voidrun(LockStepJob... jobs) booleanthread(int which) Method to call around each part to be executed by a single thread.
-
Field Details
-
n
protected int n -
barrier
-
throwable
-
-
Constructor Details
-
LockStepJob
public LockStepJob()
-
-
Method Details
-
initialize
Run the thread n (1, 2...). -
run
public void run() -
thread
Method to call around each part to be executed by a single thread.- Parameters:
which- which thread is concerned- Returns:
trueif the code should be executed- Throws:
Exception
-
job
Override this to define the actual job to execute in multiple threads.- Throws:
Exception
-
run
- Throws:
Exception
-