aspose file tools*
The moose likes Threads and Synchronization and the fly likes A Simple Problem with join()... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "A Simple Problem with join()..." Watch "A Simple Problem with join()..." New topic
Author

A Simple Problem with join()...

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
Dear Friends, i have written a simple program...





The output is...

One : 0..<>One : 1..<>One : 2..<>One : 3..<>One : 4..<>
Two : 0..<>Two : 1..<>Two : 2..<>Two : 3..<>Two : 4..<>
Three : 0..<>Three : 1..<>Three : 2..<>Three : 3..<>Three : 4..<>

Press any key to continue...




My problem is i dont understand who is joining whom,
i actually dont know how join() works,
i have read the book, but it still is not very clear to me...

Regards
Prashanth Lingala


Have A Nice Day !!!
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
The join() method, when called on thread "t" for instance, makes the currently executing thread (main in your case) wait until thread "t" dies (the run() method returns).


James Carman, President<br />Carman Consulting, Inc.
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hello Prashanth,

t.join() may be read as : "stop the execution at this point until t has finished". In your sample code, the JVM creates a thread (named "main thread") in which your application runs then main()creates and starts 3 other threads. The join() methods simply force the main thread to stop until t1 and t2 has died (at the end of the run() method).

Hope that helps,


Lionel Badiou
CodeFutures Software
Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
Thanks James and Lionel
Thank you

Regards
Prashanth Lingala
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Moving to our "Threads and Synchronization" forum.


[Jess in Action][AskingGoodQuestions]
 
Consider Paul's rocket mass heater.
 
subject: A Simple Problem with join()...
 
Similar Threads
Thread doubt
Output even more unexpected than I was expecting!
Doubt in join method
Thread synchronisation - Using a string literal for locking
Thread