@@ -0,0 +1,1784 @@
+package jdk.concurrent;%0A%0A/**%0A * http://www.cnblogs.com/cyfonly/p/5800758.html%0A */%0Apublic class FalseShareTest implements Runnable %7B%0A    public static int NUM_THREADS = 4;%0A    public final static long ITERATIONS = 500L * 1000L * 1000L;%0A    private final int arrayIndex;%0A    private static VolatileLong%5B%5D longs;%0A    public static long SUM_TIME = 0l;%0A%0A    public FalseShareTest(final int arrayIndex) %7B%0A        this.arrayIndex = arrayIndex;%0A    %7D%0A%0A    public static void main(final String%5B%5D args) throws Exception %7B%0A        Thread.sleep(10000);%0A        for (int j = 0; j %3C 10; j++) %7B%0A            System.out.println(j);%0A            if (args.length == 1) %7B%0A                NUM_THREADS = Integer.parseInt(args%5B0%5D);%0A            %7D%0A            longs = new VolatileLong%5BNUM_THREADS%5D;%0A            for (int i = 0; i %3C longs.length; i++) %7B%0A                longs%5Bi%5D = new VolatileLong();%0A            %7D%0A            final long start = System.nanoTime();%0A            runTest();%0A            final long end = System.nanoTime();%0A            SUM_TIME += end - start;%0A        %7D%0A        System.out.println(%22%E5%B9%B3%E5%9D%87%E8%80%97%E6%97%B6%EF%BC%9A%22 + SUM_TIME / 10);%0A    %7D%0A%0A    private static void runTest() throws InterruptedException %7B%0A        Thread%5B%5D threads = new Thread%5BNUM_THREADS%5D;%0A        for (int i = 0; i %3C threads.length; i++) %7B%0A            threads%5Bi%5D = new Thread(new FalseShareTest(i));%0A        %7D%0A        for (Thread t : threads) %7B%0A            t.start();%0A        %7D%0A        for (Thread t : threads) %7B%0A            t.join();%0A        %7D%0A    %7D%0A%0A    public void run() %7B%0A        long i = ITERATIONS + 1;%0A        while (0 != --i) %7B%0A            longs%5BarrayIndex%5D.value = i;%0A        %7D%0A    %7D%0A%0A    public final static class VolatileLong %7B%0A        public volatile long value = 0L;%0A        public long p1, p2, p3, p4, p5, p6;     //%E5%B1%8F%E8%94%BD%E6%AD%A4%E8%A1%8C%0A    %7D%0A%7D

false share