Class SequenceLock


  • public class SequenceLock
    extends Object
    Lock mechanism to let multiple threads execute phases sequentially.
    Author:
    Kohsuke Kawaguchi
    • Constructor Detail

      • SequenceLock

        public SequenceLock()
    • Method Detail

      • phase

        public void phase​(int i)
                   throws InterruptedException
        Blocks until all the previous phases are completed, and returns when the specified phase i is started. If the calling thread was executing an earlier phase, that phase is marked as completed.
        Throws:
        IllegalStateException - if the sequential lock protocol is aborted, or the thread that owns the current phase has quit.
        InterruptedException
      • done

        public void done()
        Marks the current phase completed that the calling thread was executing.

        This is only necessary when the thread exits the last phase, as phase(int) call implies the done() call.

      • abort

        public void abort()
        Tell all the threads that this sequencing was aborted. Everyone waiting for future phases will receive an error.

        Calling this method from the finally block prevents a dead lock if one of the participating thread aborts with an exception, as without the explicit abort operation, other threads will block forever for a phase that'll never come.