public class BlockerSync extends Object
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 and Description |
---|
BlockerSync() |
Modifier and Type | Method and Description |
---|---|
void |
awaitBlocker()
Waits until the blocking thread has entered the method
block() or blockNonInterruptible() . |
void |
block()
Blocks until
releaseBlocker() is called or this thread is interrupted. |
void |
blockNonInterruptible()
Blocks until
releaseBlocker() is called. |
void |
releaseBlocker()
Lets the blocked thread continue.
|
public void awaitBlocker() throws InterruptedException
block()
or blockNonInterruptible()
.InterruptedException
public void block() throws InterruptedException
releaseBlocker()
is called or this thread is interrupted. Notifies the
awaiting thread that waits in the method awaitBlocker()
.InterruptedException
public void blockNonInterruptible()
releaseBlocker()
is called. Notifies the awaiting thread that waits in
the method awaitBlocker()
.public void releaseBlocker()
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.