Class SequenceLock

java.lang.Object
org.jvnet.hudson.test.SequenceLock

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Tell all the threads that this sequencing was aborted.
    void
    Marks the current phase completed that the calling thread was executing.
    void
    phase(int i)
    Blocks until all the previous phases are completed, and returns when the specified phase i is started.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SequenceLock

      public SequenceLock()
  • Method Details

    • 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.