Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

join()

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not quite sure what this method can do to threads. can anyone help?
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by adam lui:
i am not quite sure what this method can do to threads. can anyone help?


It doesn't do anything to the thread that you are trying to join().

Basically, it causes the current thread, to wait until the thread, that you are trying to join with, to exits. When that thread is no longer alive, the join() method will return.

Henry
 
Srikanth Iyer
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are two froms of the join method.....................

1) final void join() throws InerruptedException

and
2) final void join(long millisex) throws InerruptedException

a call to both these methods invoed on athread will wait and not reutrn until either the thread has completed or it is timed out after the specificed time, respectively......


that is the first thread waits for the second thread to join in after completeion.
A running thread t1 invokest the method join() on a thread t2.

The join has no effect if threadt2 has already completed. if t2 is alice then t1 transits to the blocked-for-join completion state. the thread t1 waits in this state until one of these occur..........

a) thread t2 completes ------ in this case t1 is enabled and when it gets to run, it will continure normally

b) thread t1 is timed out (time specified int he argument as in (2))

c) thread t1 is interrupted --------- then the InerruptedException will be thrown.........
 
suresh mulagala
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this..



here th1.join() will make th1 execute completely and finish before th2 starts to execute.
[ October 02, 2007: Message edited by: suresh mulagala ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic