java基础 并发测试代码

This commit is contained in:
wyl
2024-07-01 00:28:32 +08:00
parent da0e11337c
commit 30d826bb8e
23 changed files with 1258 additions and 25 deletions
@@ -0,0 +1,27 @@
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);
}
}