IntelliJ Java IDE
The moose likes Threads and Synchronization and the fly likes How2 react when mutliple threads finish Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How2 react when mutliple threads finish" Watch "How2 react when mutliple threads finish" New topic
Author

How2 react when mutliple threads finish

Tom Hughes
Ranch Hand

Joined: Feb 09, 2002
Posts: 86
Hi,
I am writing a java client. On startup, it does the following for three different
sets of data (templates, pages and facts).
Send request to server.
Decode reply.
It currently does this serially and I want to multi-thread it.
I know how to spawn 3 threads (one for each set of data).
What I want to do is,
Spawn my three threads.
Wait until they're all finished.
Do something else.
What is the best way to do the "Wait until they're all finished." bit ?
thanks,
Tom
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Look into Thread.join(Thread). This will cause the calling thread to wait until the indicated other thread finishes.
- Peter
Tom Hughes
Ranch Hand

Joined: Feb 09, 2002
Posts: 86
Cheers Peter,
This is the code I came up with. Is it optimal ?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Yep, that's the idea
- Peter
 
IntelliJ Java IDE
 
subject: How2 react when mutliple threads finish
 
Threads others viewed
jsp/servlet executes business method
what is work of join() method of class Thread
Why no join() method in ThreadGroup?
how to check if all threads are finished?
join() synchronizes the threads?
developer file tools