资 源 简 介
package com;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;public class VolatileTest {public static void main(String[] args) throws InterruptedException {final Counter counter = new Counter();ExecutorService threadPool = Executors.newCachedThreadPool();for (int i = 0; i < 1000; i++) {/*new Thread() {@Overridepublic void run() {counter.inc();};}.start();*/threadPool.execute(new Runnable() {@Overridepublic void run() {counter.inc();}});}// Thread.sleep(3000);System.out.println(counter);}}