• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

join()

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not quite sure what this method can do to threads. can anyone help?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic