Originally posted by Anthony Smith:
I have a class that implements Runnable. The main method of this class just starts threads. When any of the threads complete, I want the program to stop. How do I do this?
That's an interesting scenario. Most of the time, you would want a particular
thread (or set of threads) to finish -- not when *any* thread in a group finish... but okay...
The best option is to modify the threads, to set some sort of DONE flag and notify the main thread, which is waiting. This main thread can then simply call System.exit().
Other option, is to have the main thread call join(), with a small timeout, in a loop, repeatedly on the threads. And call System.exit() if any of those don't return by timeout.
Henry