当前位置: 代码迷 >> J2SE >> java 线程 中的join方法解决思路
  详细解决方案

java 线程 中的join方法解决思路

热度:456   发布时间:2016-04-24 02:28:43.0
java 线程 中的join方法
在java的tutorial中有这样一段描述

Joins

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.

怎么感觉红色的两句话有点自相矛盾呢。

------解决方案--------------------
不矛盾,t.join();之后先是执行t,再执行当前线程;第一句话中所谓的one thread指的是当前运行的线程,another指的是线程t
------解决方案--------------------
join 等同于排队。

我排在你后面哦,我【等】你做完了,我再继续做。
  相关解决方案