标签:uda ref null 一个 vol lan extend lang 操作
package demo1;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by liudan on 2017/7/2.
*/
public class MyThread_volatile2 extends Thread{
private static volatile int count;
/*AtomicInteger:使用步长一次性加10*/
private static void addCount(){
for (int i=0;i<1000;i++){
count++;
}
System.err.println(count);
}
@Override
public void run() {
addCount();
}
public static void main(String[] args){
MyThread_volatile2[] myThread_volatile2 = new MyThread_volatile2[10];
for (int i=0;i<myThread_volatile2.length;i++){
myThread_volatile2[i] = new MyThread_volatile2();
}
for (int i=0;i<10;i++){
myThread_volatile2[i].start();
}
}
}
输出:
1000 2000 3000 4000 5309 6716 7716 5716 8716 9716
标签:uda ref null 一个 vol lan extend lang 操作
原文地址:http://www.cnblogs.com/xxt19970908/p/7302410.html