Is there any method by which I can join() to a group of threads instead of a single one?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sanjay_acharya
Posted On:   Thursday, April 19, 2001 10:25 AM

Is there any method by which I can join() to a group of threads instead of a single one?

Re: Is there any method by which I can join() to a group of threads instead of a single one?

Posted By:   Anonymous  
Posted On:   Friday, April 27, 2001 12:06 AM

I recommend that you subclass ThreadGroup and then create one (or more) join-methods in that class.

When the join method is called just iterate and join the threads in the threadgroup.

public class ExtendedThreadGroup extends ThreadGroup{

public ExtendedThreadGroup(String aName){

super(aName);

}

public ExtendedThreadGroup(String aName, ThreadGroup

aThreadGroup){

super(aName,aThreadGroup);

}

public void join(){

Thread threads[];enumerate(threads);

for(int i= 0;i
threads[i].join();

}

}



Thats IT ;)

Is there any method by which I can join() to a group of threads instead of a single one?!_NEWLINE_!

Posted By:   Alex_Chaffee  
Posted On:   Tuesday, April 24, 2001 06:51 AM

Yes. Just join to each one in turn. That way, when the loop exits, you know that all the threads have exited -- whether it was the first thread or the seventh thread that took the longest, all threads will be waited for. Remember, join() on a thread that's already exited takes no time.



Iterator i = myThreads.iterator();
while (i.hasNext()) {
((Thread)i.next()).join();
}
About | Sitemap | Contact