Valhalla Legends Archive

Programming => General Programming => Java Programming => Topic started by: DarkOne on April 16, 2004, 01:05 AM

Title: Question about Thread.join()
Post by: DarkOne on April 16, 2004, 01:05 AM
What exactly does this method do? Is it used in connection with synchronization in some way? I'm uderstanding the use of this method in two ways:

1) Actually waits for a thread started before (Thread.start() is invoked on a thread before another thread) and executed when that thread is done executing.

2) Waits for an oppertunity to safely 'interrupt' the execution of the previous thread and begins executing for some interval of time.

Sorry if my wording is a bit confusing.
Title: Re:Question about Thread.join()
Post by: Tuberload on April 16, 2004, 02:45 AM
It allows a thread to wait untill another thread is done executing. So say you want a specific thread to always be the last thread executed when a program exits. You would have it call the join() method on all the other running threads, and it would then wait for them to finish.
Title: Re:Question about Thread.join()
Post by: iago on April 16, 2004, 06:49 AM
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#join()

Basically, what Tuberload said, "Waits for the thread to die"
Title: Re:Question about Thread.join()
Post by: Tuberload on April 16, 2004, 01:57 PM
Quote from: iago on April 16, 2004, 06:49 AM
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#join()

Basically, what Tuberload said, "Waits for the thread to die"

Ah, never thought to point him to the documentation. :)
Title: Re:Question about Thread.join()
Post by: DarkOne on April 16, 2004, 08:46 PM
Quote from: Tuberload on April 16, 2004, 01:57 PM
Quote from: iago on April 16, 2004, 06:49 AM
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#join()

Basically, what Tuberload said, "Waits for the thread to die"

Ah, never thought to point him to the documentation. :)

No need to point me there. I use the documentation whenever necessary, I read there first, but I found their description of the join() function a bit unclear.

Thanks for the replies iago and tuberload.