Waiting on threads

Posted by Paul Reiners on Stack Overflow See other posts from Stack Overflow or by Paul Reiners
Published on 2010-04-05T19:42:34Z Indexed on 2010/04/05 21:13 UTC
Read the original article Hit count: 138

Filed under:
|
|

I have a method that contains the following (Java) code:

doSomeThings();
doSomeOtherThings();

doSomeThings() creates some threads, each of which will run for only a finite amount of time. The problem is that I don't want doSomeOtherThings() to be called until all the threads launched by doSomeThings() are finished. (Also doSomeThings() will call methods that may launch new threads and so on. I don't want to execute doSomeOtherThings() until all these threads have finished.)

This is because doSomeThings(), among other things will set myObject to null, while doSomeOtherThings() calls myObject.myMethod() and I do not want myObject to be null at that time.

Is there some standard way of doing this kind of thing (in Java)?

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about wait