public static void main(String[] args) { Lock rl = new ReentrantLock(); try { rl.lock(); System.out.println("--1" + rl); rl.lockInterruptibly(); System.out.println("--2" + rl); rl.lock(); // rl.lockInterruptibly(); synchronized (rl) { System.out.println("--3" + rl); } System.out.println("--4" + rl); } catch (InterruptedException e) { e.printStackTrace(); } finally { // 解锁 // rl.unlock(); // rl.unlock(); } } }
}
把unlock注释掉,输出lock的状态,发现被main线程解锁了,
为什么main线程会解锁
红糖糍粑
相关分类