EDU.oswego.cs.dl.util.concurrent
Class Latch
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.Latch
- Sync
public class Latch
extends java.lang.Object
A latch is a boolean condition that is set at most once, ever.
Once a single release is issued, all acquires will pass.
Sample usage. Here are a set of classes that use
a latch as a start signal for a group of worker threads that
are created and started beforehand, and then later enabled.
class Worker implements Runnable {
private final Latch startSignal;
Worker(Latch l) { startSignal = l; }
public void run() {
startSignal.acquire();
doWork();
}
void doWork() { ... }
}
class Driver { // ...
void main() {
Latch go = new Latch();
for (int i = 0; i <32N; ++i) // make threads
new Thread(new Worker(go)).start();
doSomethingElse(); // don't let run yet
go.release(); // let all threads proceed
}
}
[
Introduction to this package. ]
latched_
protected boolean latched_
acquire
public void acquire()
throws InterruptedException
- acquire in interface Sync
attempt
public boolean attempt(long msecs)
throws InterruptedException
- attempt in interface Sync
release
public void release()
Enable all current and future acquires to pass *
- release in interface Sync