• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

join()  RSS feed

 
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?
 
author
Sheriff
Posts: 23569
138
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
 
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.........
 
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!