随记:
AtomicInteger
public class ExampleUnitTest {
public ExampleUnitTest() {
int a = P.getI();
System.out.println(a);
}
@Test
public void testAtomicInteger() {
// 原子性操作AtomicInteger
print("****");
new ExampleUnitTest();
new ExampleUnitTest();
}
private static final class P{
public static int getI() {
return atomicInteger.incrementAndGet();
}
private static AtomicIntegeratomicInteger =new AtomicInteger();
}
/*
打印结果
1****
2
3
*/
}