原子变量
public class Test {
public static void main(String[] args) {
AtomicInteger at = new AtomicInteger();
for (int i = 0; i < 3; i++) {
MyThread t = new MyThread(at, i);
t.start();
}
}
}
class MyThread extends Thread {
private AtomicInteger at;
private int index;
public MyThread(AtomicInteger at, int index) {
this.at = at;
this.index = index;
}
@
Override public void run() {
while(true) {
if(at.get() % 3 == index) {
System.out.print((char)('a' + index));
at.incrementAndGet();
}
}
}
}