It does not use events, but I am just one of them, I am sure that many ways to do this. A quick warning: to do this, you will need to include the Runnable object in the Thread object or change your interface to have any isStopped () method in your Runnable that returns whether your Runnable was still running.
Perhaps the parent thread keeps track of all the child threads in the list. When the child thread ends, put the value that it calculates in some field, say, the result, and create a method called getResult ().
Periodically iterate over the parent thread through the list and check if the thread is stopped. If you create a Runnable to Thread object, there is a method called isAlive () to determine if the thread is stopped. If it is, call getResult () and do whatever.
In the parent thread you can do this:
Boolean running = true; while (running) { //iterate through list //if stopped, get value and do whatever //if all the child threads are stopped, stop this thread and do whatever Thread.sleep(1000); //makes this parent thread pause for 1 second before stopping again }
source share