public class Count implements java.lang.Runnable{
String threadName;
AtomicInteger a;
public Count(String threadName,AtomicInteger a){
this.threadName = threadName;
this.a = a;
}
@Override
public void run() {
while(true){
if(this.a.get()>100)break;
System.out.println(this.threadName+" "+this.a.addAndGet(1));
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
AtomicInteger a = new AtomicInteger(0);
new Thread(new test().new Count("1",a)).start();
new Thread(new test().new Count("2",a)).start();
new Thread(new test().new Count("3",a)).start();
}
高并发---AtomicInteger
最新推荐文章于 2024-05-15 16:15:50 发布