Concurrency

《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/

《Java并发编程从入门到精通》:http://ifeve.com/%E3%80%8A-java%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E7%B2%BE%E9%80%9A%E3%80%8B%E7%9B%AE%E5%BD%95%E5%92%8C%E5%BA%8F%E8%A8%80/#more-20914

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 InterruptedException
Waits 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 InterruptedException
Waits at most millis milliseconds for this thread to die. A timeout of 0 means to wait forever.

This implementation uses a loop of this.wait calls conditioned on this.isAlive. As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.

Parameters:
millis - the time to wait in milliseconds
Throws:
IllegalArgumentException - if the value of millis is negative
InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
 
 
 
 
原文地址:https://www.cnblogs.com/beidoufeng/p/6226782.html