ReentrantLock可重入锁
大概解析一下ReentrantLock可重入锁,具体的描述网上很多大神有更加详细切专业的解答。
可重入锁即你可以对一个线程加10(最大是2147483647,int的最大值)把锁,但是你在释放锁的时候同样也要释放这10把锁。
发现问题
在学习ReentrantLock时写一段这样的代码:
public class Reentrant_Demo {
static Lock lock = new ReentrantLock();
public static void main(String[] args) throws InterruptedException {
lock.lock();
System.out.println(Thread.currentThread().getName()+"加第1次锁");
lock.lock();
System.out.println(Thread.currentThread().getName