EDU.oswego.cs.dl.util.concurrent
public class CountDown extends Object implements Sync
Sample usage. Here are a set of classes in which a group of worker threads use a countdown to notify a driver when all threads are complete.
class Worker implements Runnable {
private final CountDown done;
Worker(CountDown d) { done = d; }
public void run() {
doWork();
done.release();
}
}
class Driver { // ...
void main() {
CountDown done = new CountDown(N);
for (int i = 0; i < N; ++i)
new Thread(new Worker(done)).start();
doSomethingElse();
done.acquire(); // wait for all to finish
}
}
| Field Summary | |
|---|---|
| protected int | count_ |
| protected int | initialCount_ |
| Constructor Summary | |
|---|---|
| CountDown(int count) Create a new CountDown with given count value * | |
| Method Summary | |
|---|---|
| void | acquire() |
| boolean | attempt(long msecs) |
| int | currentCount()
Return the current count value.
|
| int | initialCount() Return the initial count value * |
| void | release()
Decrement the count.
|