![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
源码分析
flowral
等风来
展开
-
Semaphore原理、源码分析
static final class NonfairSync extends Sync { private static final long serialVersionUID = -2694183684443567898L; NonfairSync(int permits) { // permits等于资源数 super(permits); } // Semaphore 方法, 方便阅读, 放在此处 public void acquire() throws Interrup.原创 2022-03-09 22:44:02 · 220 阅读 · 0 评论 -
读写锁加锁流程以及源码分析
读写锁接口结构public interface ReadWriteLock { //读锁上锁 Lock readLock(); //写锁上锁 Lock writeLock();}以下源码摘自ReentrantReadWriteLock一、写锁上锁static final class NonfairSync extends Sync { // ... 省略无关代码 // 外部类 WriteLock 方法, 方便阅读, 放在此处 public void lock()原创 2022-03-09 22:32:34 · 421 阅读 · 0 评论 -
ReentrantLock锁底层原理(加锁、解锁、可打断模式、公平锁、条件变量等源码)
一、加锁1、lock()final void lock() { //先尝试直接加锁 if (compareAndSetState(0, 1)) //成功了就结束方法 setExclusiveOwnerThread(Thread.currentThread()); else //失败了调用acquire(1) acquire(1);}2、acquire(1)public final void acquire(int arg) {原创 2021-11-11 16:59:56 · 735 阅读 · 0 评论