《Concurrency》:http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
《Concurrency中文翻译》:http://ifeve.com/oracle-java-concurrency-tutorial/
《Java并发结构》:http://ifeve.com/java-concurrency-constructs/
《Java并发性和多线程介绍》:http://ifeve.com/java-concurrency-thread-directory/
2016-12-27 17:38:22
Join
The join
method allows one thread to wait for the completion of another. If t
is a Thread
object whose thread is currently executing,
t.join();
causes the current thread to pause execution until t
's thread terminates. Overloads of join
allow the programmer to specify a waiting period. However, as with sleep
, join
is dependent on the OS for timing, so you should not assume that join
will wait exactly as long as you specify.
Like sleep
, join
responds to an interrupt by exiting with an InterruptedException
.
public final void join()
throws InterruptedExceptionWaits for this thread to die.An invocation of this method behaves in exactly the same way as the invocation
join
(0)
- Throws:
InterruptedException
- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
public final void join(long millis)
throws InterruptedExceptionWaits at mostmillis
milliseconds for this thread to die. A timeout of0
means to wait forever.This implementation uses a loop of
this.wait
calls conditioned onthis.isAlive
. As a thread terminates thethis.notifyAll
method is invoked. It is recommended that applications not usewait
,notify
, ornotifyAll
onThread
instances.
- Parameters:
millis
- the time to wait in milliseconds- Throws:
IllegalArgumentException
- if the value ofmillis
is negativeInterruptedException
- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.