摘要: 非公平锁与公平锁解锁 唤醒挂起的线程,将state设置无锁即为0.注:如果多次获取相同的锁,就必须释放多少次。 /** * Attempts to release this lock. * * <p>If the current thread is the holder of this lock t 阅读全文
posted @ 2020-03-26 21:24 柳无情 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 非公平锁加锁 · 1)当前线程能加锁,设置当前持有锁的线程为当前线程;否则会再次获取锁,获取不成功加入等待队列 /** * Performs lock. Try immediate barge, backing up to normal * acquire on failure. */ final 阅读全文
posted @ 2020-03-26 21:21 柳无情 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 原理与概念 1.ReentrantLock原理:多个线程获取锁,一个线程获取到锁,其他线程排队等待锁,并挂起;当获取到锁这个节点释放锁,就会唤醒队伍的头结点。 2.ReentrantLock是个可重入锁,支持公平锁和非公平锁。ReentrantLock默认使用非公平锁,看源码可知。 /** * Cr 阅读全文
posted @ 2020-03-26 21:20 柳无情 阅读(2276) 评论(0) 推荐(0) 编辑