Hi,
From my main thread, i am spawning few child threads.
Code:AnObject obj = new AnObject(); for(int i =0;i<someInt;i++) { ATarget aTarget = new ATarget(obj); Thread t = new Thread(aTarget); t.start(); } obj.waitForAllThreadsAndDoSomething();
In the last method call, i want to do something which requires all the threads to be finished processing. One brute force approach is to implement the method waitForAllThreadsAndDoSomething() in the following manner:
Code:while(true) { if(aCounter >= childrenThreadsCount) { //do something } }
but this is too ugly and memory consuming.
can anyone suggest a cleaner approach by using methods in thread class like: wait(), notify(), yeild() ?
cheers


Reply With Quote


Bookmarks