开发者社区> 问答> 正文

Java中用CyclicBarrier以及CountDownLatch和join相比有什么不同

感觉join就可以解决问题啊,为什么要有CyclicBarrier和CountDownLatch

展开
收起
蛮大人123 2016-03-04 17:29:35 2421 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    第一个. 用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

    1. It is recommended that applications not use wait, notify,
    2. notifyAll on Thread instances.

    Effective Java第二版里说的很好, wait/nofify 和java.util.concurrent提供的功能比起来, 就好像是 并发汇编语言(concurrency assembly language) 一样. 更难用而且也更容易出bug.

    2019-07-17 18:52:37
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载