-
How to wait for threads to finish executing?
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
-
Re: How to wait for threads to finish executing?
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
>
>
-
Re: How to wait for threads to finish executing?
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
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks