摘要:
https://blog.csdn.net/youzi1394046585/article/details/106360141 阅读全文
posted @ 2020-09-01 17:18
小窝蜗
阅读(563)
评论(0)
推荐(0)
摘要:
https://blog.csdn.net/youzi1394046585/article/details/77603487 阅读全文
posted @ 2020-09-01 17:17
小窝蜗
阅读(233)
评论(0)
推荐(0)
摘要:
public class CASLock { //AtomicInteger是引用类型,final保证堆内存中地址不变,不保证栈内存中引用不改变 private final AtomicInteger value= new AtomicInteger(0); //持有锁的线程才有权限解锁 priva 阅读全文
posted @ 2020-09-01 16:39
小窝蜗
阅读(182)
评论(0)
推荐(0)
摘要:
源码: public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException { if (Thread.interrupted()) throw new Interrupt 阅读全文
posted @ 2020-09-01 16:34
小窝蜗
阅读(93)
评论(0)
推荐(0)
摘要:
1.介绍 基于AQS实现同步器, CountDownLatch 用同步状态持有当前计数, countDown方法调用 release从而导致计数器递减; 当计数器为0时,解除所有线程的等待; await调用acquire,如果计数器为0,acquire 会立即返回,否则阻塞。 通常用于某任务需要等待 阅读全文
posted @ 2020-09-01 16:24
小窝蜗
阅读(196)
评论(0)
推荐(0)
摘要:
1.方法入口: public final void acquireShared(int arg) { if (tryAcquireShared(arg) < 0) doAcquireShared(arg); } 执行tryAcquireShared方法获取资源,若获取成功则直接返回,若失败, 则进入 阅读全文
posted @ 2020-09-01 15:55
小窝蜗
阅读(194)
评论(0)
推荐(0)
摘要:
1.unparkSuccessor(Node) 该方法主要用于唤醒等待队列中的下一个阻塞线程。 private void unparkSuccessor(Node node) { // 获取当前节点的ws值 int ws = node.waitStatus; // 将当前节点的ws值置0 if (w 阅读全文
posted @ 2020-09-01 15:44
小窝蜗
阅读(238)
评论(0)
推荐(0)
摘要:
1.acquireQueued(Node, int) 源码: final boolean acquireQueued(final Node node, int arg) { // 标识是否获取资源失败 boolean failed = true; try { // 标识当前线程是否被中断过 bool 阅读全文
posted @ 2020-09-01 15:35
小窝蜗
阅读(1704)
评论(2)
推荐(1)
摘要:
1.获取资源(独占模式) acquire(int) 首先讲解独占模式(Exclusive)下的获取/释放资源过程,其入口方法为: public final void acquire(int arg) { if (!tryAcquire(arg) && acquireQueued(addWaiter( 阅读全文
posted @ 2020-09-01 14:54
小窝蜗
阅读(255)
评论(0)
推荐(0)
摘要:
1.介绍: AQS指的是AbstractQueuedSynchronizer(队列同步器), AQS是JDK下提供的一套用于实现基于FIFO等待队列的阻塞锁和相关的同步器的一个同步框架。 ReentrantLock、Semaphore、CountDownLatch、CyclicBarrier等并发类 阅读全文
posted @ 2020-09-01 14:38
小窝蜗
阅读(234)
评论(0)
推荐(0)

浙公网安备 33010602011771号