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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 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:
true
if 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
-