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)?