原子更新int
public class AtomicUpdaterTest {
public static void main(String[] args) {
AtomicIntegerFieldUpdater<Person> age = AtomicIntegerFieldUpdater.newUpdater(Person.class, "age");
Person person = new Person();
for (int i = 0; i < 10; i++) {
new Thread(() -> System.out.println( age.getAndIncrement(person))).start();
}
}
static class Person {
volatile int age;
}
}