• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to group the threads together ?  RSS feed

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to group the threads together in order to communicate with each other? How do the threads communicate with each other in a particular group? How to create a thread group? What are the methods in the thread group? Can we use join () method in Thread group?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of communication do you mean?
As for join()ing multiple threads, you have a few options. One is to just iterate over the threads and call join() individually on each. A more bells-and-whistles approach would be to use Doug Lea's CyclicBarrier.
You might have code that looks something like this:

Where MyThread does something like this:

That's actually not such a great solution though -- all the threads are still in existance waiting around for the others. A better solution would be one where each thread left a message right before quitting. Here's one way of implementing that:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!