package J20250802.demo02;

/**
 * @author WanJl
 * @version 1.0
 * @title MyAtomThread
 * @description
 * @create 2025/8/2
 */
public class MyAtomThread implements Runnable{
    private volatile int count=0;   //计数

    Object lock=new Object();
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            synchronized (lock){
                count++;    //并不是原子性，它在执行过程中，有可能会被其他线程打断
                System.out.println(Thread.currentThread().getName()+"第"+(i+1)+"次，当前count的值为："+count);
            }
        }
    }
}
