Demo01.java 939 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package J20250802;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo01
  6. * @description
  7. * @create 2025/8/2
  8. */
  9. public class Demo01 {
  10. public static void main(String[] args) {
  11. Thread t1=new Thread(()->{
  12. while (Money.money==100000){
  13. }
  14. System.out.println("金额已经不是10万了..当前金额为:"+Money.money);
  15. },"线程1");
  16. Thread t2=new Thread(()->{
  17. try {
  18. Thread.sleep(1000);
  19. } catch (InterruptedException e) {
  20. e.printStackTrace();
  21. }
  22. Money.money = 90000;
  23. System.out.println("经过" + Thread.currentThread().getName() + "的操作,金额变为" + Money.money);
  24. },"线程2");
  25. t1.start();
  26. t2.start();
  27. }
  28. }
  29. class Money{
  30. public static int money=100000;
  31. public static Object obj=new Object();
  32. }