BlankI have a java program that create multiple threads. I want to wait
inside the mothed that created these threads until all the threads are done
executing.
What do I need to do to accomplish this task?
TIA,
Haytham
htale@hciasachs.com
Printable View
BlankI have a java program that create multiple threads. I want to wait
inside the mothed that created these threads until all the threads are done
executing.
What do I need to do to accomplish this task?
TIA,
Haytham
htale@hciasachs.com
You probably need a seperate monitor thread, that has some synchronised
trigger in identifying that a thread is starting and finishing, then you can
poll that and see if any threads are not finished.
Pseudo-code
thread starts
tells monitor its started (active thread count is now 1)
active threads +=1
thread starts
tells monitor its started (active thread count is now two)
active threads +=1
thread ends
tells monitor its finished
active threads +-1 (active thread count is now 1)
Regards
John Timney (MVP)
Haytham <htale@hciasachs.com> wrote in message
news:3987348a@news.devx.com...
> BlankI have a java program that create multiple threads. I want to wait
> inside the mothed that created these threads until all the threads are
done
> executing.
>
> What do I need to do to accomplish this task?
>
> TIA,
> Haytham
> htale@hciasachs.com
>
>
Try the join() method of the thread. Quote from the Javadoc:
join()
Waits for this thread to die.
You will have to execute join() on each thread you want to wait for.
Haytham <htale@hciasachs.com> wrote in message
news:3987348a@news.devx.com...
> BlankI have a java program that create multiple threads. I want to wait
> inside the mothed that created these threads until all the threads are
done
> executing.
>
> What do I need to do to accomplish this task?
>
> TIA,
> Haytham
> htale@hciasachs.com
>
>