您的位置:首页 > 编程语言 > Java开发

The Java™ Tutorials — Concurrency :Joins 插入

2016-02-11 11:23 357 查看


The Java™ Tutorials — Concurrency :Joins 插入

原文地址:https://docs.oracle.com/javase/tutorial/essential/concurrency/join.html


关键点

join定义:
t.join()
会引起当前线程暂停执行直到t线程执行完毕
join也会抛出InterruptedException
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,

join 方法可以让一个线程等待另一线程的完成。如果t是一个Thread对象,而且为正在执行的对象,

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.

会引起当前线程暂停执行直到t线程执行完毕。join的重载允许开发者指定等待时间。然而,同sleep一样,join的实际等待时间同样依赖于操作系统,所以你不应该假定join的等待时长会精确地等于你所指定的时间。

Like sleep, join responds to an interrupt by exiting with an InterruptedException.

类似sleep,join在响应中断时,会退出并抛出InterruptedException异常。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息