1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-08-10 00:41:37 +08:00

Compare commits

..

No commits in common. "9a5f864125d6cb889de54b54a167940255499311" and "e842996bf106eddbecb656f0f64db13db4d92662" have entirely different histories.

2 changed files with 3 additions and 3 deletions

View File

@ -728,7 +728,7 @@ public final boolean releaseShared(int arg) {
### CountDownLatch 的原理是什么? ### CountDownLatch 的原理是什么?
`CountDownLatch` 是共享锁的一种实现,它默认构造 AQS 的 `state` 值为 `count`。当线程使用 `countDown()` 方法时,其实使用了`tryReleaseShared`方法以 CAS 的操作来减少 `state`,直至 `state` 为 0 。当调用 `await()` 方法的时候,如果 `state` 不为 0那就证明任务还没有执行完毕`await()` 方法就会一直阻塞,也就是说 `await()` 方法之后的语句不会被执行。直到`count` 个线程调用了`countDown()`使state值被减为0或者调用`await()`的线程被中断,该线程才会从阻塞中被唤醒`await()` 方法之后的语句得到执行。 `CountDownLatch` 是共享锁的一种实现,它默认构造 AQS 的 `state` 值为 `count`。当线程使用 `countDown()` 方法时,其实使用了`tryReleaseShared`方法以 CAS 的操作来减少 `state`,直至 `state` 为 0 。当调用 `await()` 方法的时候,如果 `state` 不为 0那就证明任务还没有执行完毕`await()` 方法就会一直阻塞,也就是说 `await()` 方法之后的语句不会被执行。然后,`CountDownLatch` 会自旋 CAS 判断 `state == 0`,如果 `state == 0` 的话,就会释放所有等待的线程`await()` 方法之后的语句得到执行。
### 用过 CountDownLatch 么?什么场景下用的? ### 用过 CountDownLatch 么?什么场景下用的?

View File

@ -201,10 +201,10 @@ Maven 在遇到这种问题的时候,会遵循 **路径最短优先** 和 **
现在知道为什么你的 Maven 项目总是会报`NoClassDefFoundError``NoSuchMethodError`错误了吧? 现在知道为什么你的 Maven 项目总是会报`NoClassDefFoundError``NoSuchMethodError`错误了吧?
**如何解决呢?** 我们可以通过`exclusion`标签手动将 X(1.0) 给排除。 **如何解决呢?** 我们可以通过`exclusive`标签手动将 X(1.0) 给排除。
```xml ```xml
<dependency> <dependencyD>
...... ......
<exclusions> <exclusions>
<exclusion> <exclusion>