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();
| 构造器和说明 |
|---|
BlockerSync() |
| 限定符和类型 | 方法和说明 |
|---|---|
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().public void block()
throws InterruptedException
releaseBlocker() is called or this thread is interrupted. Notifies the
awaiting thread that waits in the method awaitBlocker().public void blockNonInterruptible()
releaseBlocker() is called. Notifies the awaiting thread that waits in
the method awaitBlocker().public void releaseBlocker()
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.