Invoking different methods on threads

Posted by Kraken on Stack Overflow See other posts from Stack Overflow or by Kraken
Published on 2012-08-28T09:23:38Z Indexed on 2012/08/28 9:38 UTC
Read the original article Hit count: 184

Filed under:
|

I have a main process main. It creates 10 threads (say) and then what i want to do is the following:

while(required){
Thread t= new Thread(new ClassImplementingRunnable());
t.start();
counter++;
}

Now i have the list of these threads, and for each thread i want to do a set of process, same for all, hence i put that implementation in the run method of ClassImplementingRunnable.

Now after the threads have done their execution, i wan to wait for all of them to stop, and then evoke them again, but this time i want to do them serially not in parallel.

for this I join each thread, to wait for them to finish execution but after that i am not sure how to evoke them again and run that piece of code serially. Can i do something like

for(each thread){
t.reevoke(); //how can i do that.
t.doThis();  // Also where does `dothis()` go, given that my ClassImplementingRunnable is an inner class.
}

Also, i want to use the same thread, i.e. i want the to continue from where they left off, but in a serial manner. I am not sure how to go about the last piece of pseudo code. Kindly help. Working with with java.

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading