Documentation

The Java™ Tutorials
Hide TOC
Joins加入
Trail: Essential Java Classes
Lesson: Concurrency
Section: Thread Objects

Joins加入

The join method allows one thread to wait for the completion of another. join方法允许一个线程等待另一个线程的完成。If t is a Thread object whose thread is currently executing,如果t是线程当前正在执行的Thread对象,

t.join();

causes the current thread to pause execution until t's thread terminates. 使当前线程暂停执行,直到t的线程终止。Overloads of join allow the programmer to specify a waiting period. join的重载允许程序员指定等待时间。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.但是,与sleep一样,join依赖于操作系统的计时,因此您不应该假设join将按照您指定的时间等待。

Like sleep, join responds to an interrupt by exiting with an InterruptedException.sleep类似,join通过使用InterruptedException退出来响应中断。


Previous page: Interrupts
Next page: The SimpleThreads Example