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/
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 mostmillismilliseconds for this thread to die. A timeout of0means to wait forever.This implementation uses a loop of
this.waitcalls conditioned onthis.isAlive. As a thread terminates thethis.notifyAllmethod is invoked. It is recommended that applications not usewait,notify, ornotifyAllonThreadinstances.
- Parameters:
millis- the time to wait in milliseconds- Throws:
IllegalArgumentException- if the value ofmillisis negativeInterruptedException- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
浙公网安备 33010602011771号