EDU.oswego.cs.dl.util.concurrent
public class Latch extends Object implements Sync
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 < N; ++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. ]
| Field Summary | |
|---|---|
| protected boolean | latched_ |
| Method Summary | |
|---|---|
| void | acquire() |
| boolean | attempt(long msecs) |
| void | release() Enable all current and future acquires to pass * |