package com.company.bingfa;
import java.util.concurrent.atomic.AtomicInteger;
class MyThread10 extends Thread{
public static AtomicInteger n;
MyThread10(AtomicInteger n){
this.n = n;
}
@Override
public void run() {
for (int i = 0; i < 1000; i++) {
n.getAndIncrement();
}
}
}
public class MyAtomicInteger {
public static void main(String[] args) throws InterruptedException {
AtomicInteger n = new AtomicInteger(0);
Thread[] threads = new Thread[100];
for (int i = 0; i < threads.length; i++) {
threads[i] = new MyThread10(n);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
System.out.println(MyThread10.n);
}
}