The difference is, I continuously created two threads, start them, and wait for both of them to finish before I start two more threads. (This is a good example of using join() )
Originally posted by Rob Ross:
When I call join, it causes the current thread to wait until the other thread has finished. When it finishes, my thread resumes.
When you call a.join() the current thread running would be the last statement b.start() which must wait until the a.start() thread has finished running.
Am I correct on this?
calling a.join() causes the current thread to wait until thread a is done executing, i.e, it's run method exits. The next line is b.join()
and this will wait until thread b is done before continuing.
Originally posted by Paul Salerno:
Rob I'm sorry I'm still a little fuzzy on this, what the "current thread is".
a.join() -- when it reaches here the current thread is B; once thread B's run method exits, Thread A is executed
b.join() -- when it reaches here the current thread is A; once thread A's run method exits, Thread B is executed
Look forward to closing this issue too.
thanks again Rob!