maohaocheng.
2021-01-21 23:36有大佬可以告诉我下面代码为啥debug跟run结果不一致吗。
public class Main { public static void main(String[] args) throws InterruptedException { Test test = new Test(); Thread thread1 = new Thread(() -> { try { System.out.println(test.change()); } catch (InterruptedException e) { e.printStackTrace(); } }); Thread thread2 = new Thread(() -> { try { System.out.println(test.change()); } catch (InterruptedException e) { e.printStackTrace(); } }); thread1.start(); TimeUnit.MILLISECONDS.sleep(8); thread2.start(); } }
public class Test { private volatile int a = 0; public int change() throws InterruptedException { while (a == 0){ TimeUnit.MILLISECONDS.sleep(10); a++; } return a; } }
- 点赞
- 回答
- 收藏
- 复制链接分享
11条回答
为你推荐
- 关于pycharm运行代码时出现Edit configuration
- python
- 1个回答
- springclound项目打包为war放在tomcat中启动报错,在idea中能正常运行,自己弄了两天了,没解决,请各位大佬帮忙,万分感谢
- spring
- java
- maven
- tomcat
- intellij-idea
- 3个回答
- 运行报错,大佬们帮忙看看什么原因java.util.concurrent.ExecutionException
- java
- 3个回答
- Spring Boot启动报错ERROR 3644 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
- spring
- java
- maven
- intellij-idea
- java-ee
- 3个回答
- 请教一下,到底我的mapper.xml哪里出错了,弄不明白为什么找不到我写的log类
- java
- spring
- xml
- tomcat
- eclipse
- 1个回答
换一换