package J20250802.demo03;

import java.util.concurrent.atomic.AtomicInteger;


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

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            int count = integer.incrementAndGet();
            //1、从共享数据中读取数据到本地线程
            //2、修改本地线程栈中的变量副本的值
            //3、会把本地线程栈中的变量副本的值赋值给共享的数据
            String name = Thread.currentThread().getName();
            System.out.println(name + "第" + (i + 1) + "次，当前count的值为：" + count);
        }
    }
}

