12345678910111213141516171819202122232425262728293031323334353637383940 |
- package J20250802;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo01
- * @description
- * @create 2025/8/2
- */
- public class Demo01 {
- public static void main(String[] args) {
- Thread t1=new Thread(()->{
- while (Money.money==100000){
- }
- System.out.println("金额已经不是10万了..当前金额为:"+Money.money);
- },"线程1");
- Thread t2=new Thread(()->{
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Money.money = 90000;
- System.out.println("经过" + Thread.currentThread().getName() + "的操作,金额变为" + Money.money);
- },"线程2");
- t1.start();
- t2.start();
- }
- }
- class Money{
- public static int money=100000;
- public static Object obj=new Object();
- }
|