This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Thread dependency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread dependency" Watch "Thread dependency" New topic

Thread dependency

nish vatsa

Joined: Oct 20, 2005
Posts: 6
I am in process of writing a program whose logic is as below

1) MAIN thread will create four child threads T1,T2,T3,T4 and will die out
2)T2 should execute(run) when T1 has finished.
3)T3 should excute(run) when T2 has finished
4)T4 should execute(run) when T3 has finished

I am nt able to implement the 2,3 and 4 condition
can anyone pls help out....
Thanks in advance
Henry Wong

Joined: Sep 28, 2004
Posts: 20022

Well, you can't really control when the run() method get called. It will be called sometime after the thread is started.

However, if you are willing to change the logic of the run() method, you can have all the threads check a shared state variable, to determine when it should perform, it part of the application.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Clapham

Joined: Oct 14, 2005
Posts: 19719

If you want to just run T1, then T2, then T3, then T4, there is no point in having separate threads to do that. One thread would work just fine.

But if you really have to do that (the only reason I can think of is that it's a homework question) then
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Thread dependency
It's not a secret anymore!