Package org.apache.flink.core.testutils
Class BlockerSync
- java.lang.Object
-
- org.apache.flink.core.testutils.BlockerSync
-
public class BlockerSync extends Object
A utility to help synchronize two threads in cases where one of them is supposed to reach a blocking state before the other may continue.Use as follows:
final BlockerSync sync = new BlockerSync(); // thread to be blocked Runnable toBeBlocked = () -> { // do something, like acquire a shared resource sync.blockNonInterruptible(); // release resource } new Thread(toBeBlocked).start(); sync.awaitBlocker(); // do stuff that requires the other thread to still hold the resource sync.releaseBlocker();
-
-
Constructor Summary
Constructors Constructor Description BlockerSync()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawaitBlocker()Waits until the blocking thread has entered the methodblock()orblockNonInterruptible().voidblock()Blocks untilreleaseBlocker()is called or this thread is interrupted.voidblockNonInterruptible()Blocks untilreleaseBlocker()is called.voidreleaseBlocker()Lets the blocked thread continue.
-
-
-
Method Detail
-
awaitBlocker
public void awaitBlocker() throws InterruptedExceptionWaits until the blocking thread has entered the methodblock()orblockNonInterruptible().- Throws:
InterruptedException
-
block
public void block() throws InterruptedExceptionBlocks untilreleaseBlocker()is called or this thread is interrupted. Notifies the awaiting thread that waits in the methodawaitBlocker().- Throws:
InterruptedException
-
blockNonInterruptible
public void blockNonInterruptible()
Blocks untilreleaseBlocker()is called. Notifies the awaiting thread that waits in the methodawaitBlocker().
-
releaseBlocker
public void releaseBlocker()
Lets the blocked thread continue.
-
-