Lock with counter

Hello all,

I wish to have a lock with the following features.

1. My main thread will create a lock with counter 5. Then my main thread will spawn n threads to perform some task. My main thread will wait for the lock forever, until the counter become 0.

2. The worker threads will decrease the lock's counter, at certain situation.

3. My main thread will continue execution, until the lock's counter become one.

Of course, I know I can do this by using wait, notify, AtomicInteger. However, I believe Java 6 should have a class for this kind of so called "lock with counter"?

If yes, may I know the name of the standard class?

Thank you very much!

[697 byte] By [KwangHooia] at [2007-11-27 7:06:50]
# 1
Sounds like you are talking about a CountDownLatch (java.util.concurrent).I'm not sure what you mean in your 3rd point since you say the main thread will be blocked until the counter becomes 0 in your 1st point.
Asbel_blaha at 2007-7-12 18:58:07 > top of Java-index,Core,Core APIs...
# 2
>> 3. My main thread will continue execution, until the lock's counter become one.Sorry. Is mistyping. Should be 0. Thanks. Ya. CountDownLatch is what I am looking for.
KwangHooia at 2007-7-12 18:58:07 > top of Java-index,Core,Core APIs...