Class 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 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
    • Constructor Detail

      • LockStepJob

        public LockStepJob()
    • Method Detail

      • initialize

        public void initialize​(int n,
                               CyclicBarrier barrier)
        Run the thread n (1, 2...).
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • 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