@@ -0,0 +1,1390 @@
+package juc;%0A%0Aimport java.util.concurrent.ForkJoinPool;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.RecursiveTask;%0A%0A/**%0A * Created by %E6%9D%8E%E6%81%92%E5%90%8D on 2017/6/19.%0A */%0Apublic class ForkJoinTest %7B%0A%0A    static class Sum extends RecursiveTask%3CLong%3E %7B%0A        private static final int THRESHOLD = 10;//%E5%8F%AF%E7%9B%B4%E6%8E%A5%E6%B1%82%E8%A7%A3%E7%9A%84%E4%B8%B4%E7%95%8C%E5%80%BC%0A        private final long from;%0A        private final long to;%0A%0A        Sum(long from, long to) %7B%0A            this.from = from;%0A            this.to = to;%0A        %7D%0A%0A        @Override%0A        protected Long compute() %7B%0A            long sum = 0;%0A            if ((to - from) %3C THRESHOLD) %7B//%E8%BE%BE%E5%88%B0%E7%9B%B4%E6%8E%A5%E6%B1%82%E8%A7%A3%E7%9A%84%E4%B8%B4%E7%95%8C%E7%82%B9%EF%BC%8C%E7%9B%B4%E6%8E%A5%E8%BF%9B%E8%A1%8C%E8%AE%A1%E7%AE%97%0A                for (long i = from; i %3C= to; i++) %7B%0A                    sum = sum + i;%0A                %7D%0A            %7D else %7B//%E9%80%92%E5%BD%92%E5%88%86%E8%A7%A3%E8%AE%A1%E7%AE%97%0A                long mid = (from + to) %3E%3E%3E 1;//%E5%8F%96%E4%B8%AD%E9%97%B4%E5%80%BC%0A                //%E4%BB%A5%E4%B8%AD%E9%97%B4%E5%80%BC%E4%B8%BA%E7%95%8C%E5%B0%86%E8%AE%A1%E7%AE%97%E4%BB%BB%E5%8A%A1%E5%88%86%E8%A7%A3%E6%89%A7%E8%A1%8C%0A                Sum left = new Sum(from, mid);%0A                left.fork();%0A                Sum right = new Sum(mid + 1, to);%0A                right.fork();%0A                //%E5%90%88%E5%B9%B6%E8%AE%A1%E7%AE%97%E7%BB%93%E6%9E%9C%0A                sum = left.join() + right.join();%0A            %7D%0A            return sum;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        ForkJoinPool forkJoinPool = new ForkJoinPool();%0A        Future%3CLong%3E result = forkJoinPool.submit(new Sum(1, 10000));%0A        System.out.println(%22Sum%EF%BC%9A%22 + result.get());//Sum%EF%BC%9A50005000%0A    %7D%0A%7D%0A

add > ForkJoinTest