Answers
第一个. 用Thread.join只能部分的实现CountDownLatch的功能. 这个看看CountDownLatch的java doc就可以了. 不多说
第二个. Thread.join用了Object.wait/notify机制. java.lang.Thread.join(long millis) java doc里写道:
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 .
Effective Java第二版里说的很好, wait/nofify 和java.util.concurrent提供的功能比起来, 就好像是 并发汇编语言(concurrency assembly language) 一样. 更难用而且也更容易出bug.
总结下: 从java1.5 有了并发包之后, 以前的 wait/notify/timer/synchorinized/同步容器 等等, 都应该尽可能的 用java 1.5并发包取代.
起个名字真是难
answered 11 years, 9 months ago