import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Start implements Runnable {
protected int count = 0;
@Override
public void run() {
while (count < 100) {
count++;
System.out.println(Thread.currentThread().getName() + " count:" + count);
}
}
public static void main(String[] args) {
Runnable runnable = new Start();
ExecutorService executorService = Executors.newFixedThreadPool(10);
for (int i = 0; i < 2; i++) {
executorService.execute(runnable);
}
executorService.shutdown();
}
}
第一次累加会重复,如果加锁就是顺序输出基本都是一个线程干活了,是不是我代码第一次读写的有问题。。。
交互式爱情
拉莫斯之舞
qq_遁去的一_1
相关分类