Package org.jvnet.hudson.test
Class SequenceLock
java.lang.Object
org.jvnet.hudson.test.SequenceLock
Lock mechanism to let multiple threads execute phases sequentially.
- Author:
- Kohsuke Kawaguchi
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Tell all the threads that this sequencing was aborted.void
done()
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.
-
Constructor Details
-
SequenceLock
public SequenceLock()
-
-
Method Details
-
phase
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 thedone()
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.
-