Package org.apache.flink.core.testutils
Class BlockerSync
java.lang.Object
org.apache.flink.core.testutils.BlockerSync
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidWaits until the blocking thread has entered the methodblock()orblockNonInterruptible().voidblock()Blocks untilreleaseBlocker()is called or this thread is interrupted.voidBlocks untilreleaseBlocker()is called.voidLets the blocked thread continue.
-
Constructor Details
-
BlockerSync
public BlockerSync()
-
-
Method Details
-
awaitBlocker
Waits until the blocking thread has entered the methodblock()orblockNonInterruptible().- Throws:
InterruptedException
-
block
Blocks 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.
-