This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Running threads in Sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Running threads in Sequence" Watch "Running threads in Sequence" New topic

Running threads in Sequence

Deep Gagan

Joined: Aug 03, 2007
Posts: 11

I have a question, suppose we have 100 threads e.g T1, T2, T3 . . . T100. I want threads to run in sequence. First T1 completes then T2, then T3….at last T100. Is there any way to implement this ?
You can say each thread prints its Name .
So my output should be
T1 T2 T3 T4.........T100


Thanks & Regards
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

well there is a way but I don't think that will be too much useful

have you heard of the join method on threads?

can you write code using join method?

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

So basically you want all those thread to run in a single thread. Instead of calling the start method call the run method.
But can you tell us why you created those threads in the first place if you didn't want multi-threaded behaviour.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link:
subject: Running threads in Sequence
Similar Threads
Synchronization issue
Threads and join
Output even more unexpected than I was expecting!
sequential execution of threads
Thread dependency