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) {
countPP;
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; iPP) {
executorService.execute(runnable);
}
executorService.shutdown();
}
}
the first accumulation will be repeated, if the lock is the sequential output is basically a thread of work, is not the first time my code read and write problems.