重入锁
Condition
读写锁
适用于读多写少
场景
死锁
final Object lockA = new Object();
final Object lockB = new Object();
new Thread() {
@Override
public void run() {
synchronized (lockB) {
System.out.println("获取锁B");
try {
sleep(3000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (lockA) {
System.out.print("t1");
}
}
}
}.start();
new Thread() {
@Override
public void run() {
synchronized (lockA) {
System.out.println("获取锁A");
try {
sleep(3000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (lockB) {
System.out.print("t2");
}
}
}
}.start();