| 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
|
 |
 |
|
|
subject: How2 react when mutliple threads finish
|
|
|