• Post Reply Bookmark Topic Watch Topic
  • New Topic

How2 react when mutliple threads finish

 
Tom Hughes
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into Thread.join(Thread). This will cause the calling thread to wait until the indicated other thread finishes.
- Peter
 
Tom Hughes
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers Peter,
This is the code I came up with. Is it optimal ?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, that's the idea
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!