• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

understanding join method

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot Henry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic