感觉join就可以解决问题啊,为什么要有CyclicBarrier和CountDownLatch
大家讲道理2017-04-17 11:27:06
The first one. Thread.join can only partially implement the function of CountDownLatch. Just look at the java doc of CountDownLatch. Not much to say
The second one. Thread.join uses the Object.wait/notify mechanism. java.lang.Thread.join(long millis) java doc writes:
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 2nd Edition said it very well. Compared with the functions provided by java.util.concurrent, wait/nofify is like concurrency assembly language. It is more difficult to use and easier to use. bug.
To summarize: After the concurrency package is available from java 1.5, the previous wait/notify/timer/synchorinized/synchronized container, etc., should be replaced by the java 1.5 concurrency package as much as possible.
阿神2017-04-17 11:27:06
http://stackoverflow.com/questions/21808814/whats-the-difference-between-cyclicbarrier-countdownlatch-and-join-in-java