This is one question that has baffled me. As i read through the topics on thread I came to understand that join() method to some extent can be used to sequence the order in which the threads are executing Now I have one question: In all the code examples provided uptill now the thread spawning another thread calls the join method on the spawned thread. By this i mean If thread A creates thread B then A calls b.wait() where b is an object of type thread B. So as of now we have join() helping us to allow the parent wait for the child. But what if I have two peer threads let's say C and D both spawned by the main thread; but I want thread D to execute only after thread C executes. How do i accomplish that. Please help me out here. I have written a sample code for the same but i dont seem to get that right. Please help me out. I can post the code if needed
- The thread that should only start after another thread has to have a reference to the thread it should join. - If the other thread is not yet alive, a call to join will not cause the first thread to wait (NEW state has to be taken into account).
I think the following class should do what you described: