GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes understanding join method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "understanding join method " Watch "understanding join method " New topic
Author

understanding join method

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

suppose i have a class that extends thread and in it i have a method mySample() as shown below. further i call mySample() from main method.



so when we enter mySample(), we will call join on the main thread and the currently running thread is also main. so what does it mean. does main thread will join with itself ? does that mean after join() call no more code will run since main thread is waiting for itself to die. ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

gurpeet singh wrote:suppose i have a class that extends thread and in it i have a method mySample() as shown below. further i call mySample() from main method.



so when we enter mySample(), we will call join on the main thread and the currently running thread is also main. so what does it mean. does main thread will join with itself ? does that mean after join() call no more code will run since main thread is waiting for itself to die. ?



The join() method is a method of the Thread class -- the method will wait for the thread (that is represented by the thread object) to finish. And if I remember correctly, if you never started it, should return immediately.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

thanks alot Henry.
 
 
subject: understanding join method