Files
JavaBasiceDemo/javaBase/src/main/java/concurrent/reentrantlock/CLHLockTest.java
T
2024-07-01 00:28:32 +08:00

27 lines
754 B
Java

package concurrent.reentrantlock;
public class CLHLockTest {
private static int cnt = 0;
public static void main(String[] args) throws Exception {
final CLHLock lock = new CLHLock();
for (int i = 0; i < 2; i++) {
new Thread(() -> {
lock.lock();
cnt++;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
lock.unLock();
}).start();
}
// 让main线程休眠10秒,确保其他线程全部执行完
Thread.sleep(10000);
System.out.println();
System.out.println("cnt----------->>>" + cnt);
}
}