• Welcome to Valhalla Legends Archive.
 

Question about Thread.join()

Started by DarkOne, April 16, 2004, 01:05 AM

Previous topic - Next topic

DarkOne

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.

Tuberload

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.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

iago

This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Tuberload

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. :)
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

DarkOne

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.