public abstract class LockStepJob extends Object implements Runnable
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...);
Modifier and Type | Field and Description |
---|---|
protected CyclicBarrier |
barrier |
protected int |
n |
protected Throwable |
throwable |
Constructor and Description |
---|
LockStepJob() |
Modifier and Type | Method and 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.
|
protected int n
protected CyclicBarrier barrier
public LockStepJob()
public void initialize(int n, CyclicBarrier barrier)
public boolean thread(int which) throws Exception
which
- which thread is concernedtrue
if the code should be executedException
public abstract void job() throws Exception
Exception
public static void run(LockStepJob... jobs) throws Exception
Exception
Copyright © 2017 Nuxeo. All rights reserved.