First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name here. Thanks!
Now, as to your question: you want to use wait() and notify(). This is the correct way for Threads to communicate in Java. It allows one thread to wait without using any CPU time, and then instantly wake up when another thread wants it to.
This is a bit involved to explain here, so it's best if you learn about it from a primary source. The Sun tutorial on Threads has all the information you'll need. In the particular, the lessons on "Synchronizing Threads" and "Thread Pools" will give you the specifics you're after -- but you should probably read the whole thing.
Note that all of the source for the Java APIs is freely available -- in fact, it comes with the JDK download and you get a chance to install it when you install the JDK. Look in your java installation directory for a file named "src.zip" containing this source.
But the answer to your question is that it's just done with a loop. Just one thread is started at a time.
Joined: Feb 13, 2004
Originally posted by Sol Mam-Orn: You may want to have a close look at the wait/notify mechanism in java. It would take some reading, but it appears to be perfect for the situaltion you describe
Thank you for the suggestion!
I have look into the detail of wait/notify/notifyAll, but it isn't exactly what I am looking for. This mechanism designed for synchronization control over a contention resource. I could use notifyAll to wake up all threads at the same time but then only one thread who won the resource contention can carry on...
What I want is wake up all threads and carry on doing their jobs at the same time without a resource contention monitor exist.
Anyway, I am kind of giving up this thought. On the other hand, java is kind of thread safe.. isn't it?