展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

锁(四):多线程debug

  • 案例
public class ReentrantLockDebugDemo {
// 变量i
private int i = 0;
// new1个reentrantLock
private ReentrantLock reentrantLock = new ReentrantLock();
// 测试用的方法
public void inCreate() {
// 获取锁
reentrantLock.lock();
try {
i++;
System.out.println(i);
} finally {
// 一定要在finall方法中释放锁
reentrantLock.unlock();
}
}
public static void main(String[] args) {
ReentrantLockDebugDemo reentrantLockDebugDemo = new ReentrantLockDebugDemo();
for (int i = 0; i < 3; i++) { // 3个线程中执行同一个方法
new Thread(() -> {
reentrantLockDebugDemo.inCreate();
}).start();
}
}
}
  • 选择线程级别debug

  • 查看线程

posted @   DogLeftover  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示