jdk/src/share/classes/java/util/concurrent/RecursiveAction.java
changeset 18790 d25399d849bc
parent 14325 622c473a21aa
equal deleted inserted replaced
18789:b518cd4045bc 18790:d25399d849bc
    61  *                 new SortTask(array, mid, hi));
    61  *                 new SortTask(array, mid, hi));
    62  *       merge(lo, mid, hi);
    62  *       merge(lo, mid, hi);
    63  *     }
    63  *     }
    64  *   }
    64  *   }
    65  *   // implementation details follow:
    65  *   // implementation details follow:
    66  *   final static int THRESHOLD = 1000;
    66  *   static final int THRESHOLD = 1000;
    67  *   void sortSequentially(int lo, int hi) {
    67  *   void sortSequentially(int lo, int hi) {
    68  *     Arrays.sort(array, lo, hi);
    68  *     Arrays.sort(array, lo, hi);
    69  *   }
    69  *   }
    70  *   void merge(int lo, int mid, int hi) {
    70  *   void merge(int lo, int mid, int hi) {
    71  *     long[] buf = Arrays.copyOfRange(array, lo, mid);
    71  *     long[] buf = Arrays.copyOfRange(array, lo, mid);
   138  *   protected void compute() {
   138  *   protected void compute() {
   139  *     int l = lo;
   139  *     int l = lo;
   140  *     int h = hi;
   140  *     int h = hi;
   141  *     Applyer right = null;
   141  *     Applyer right = null;
   142  *     while (h - l > 1 && getSurplusQueuedTaskCount() <= 3) {
   142  *     while (h - l > 1 && getSurplusQueuedTaskCount() <= 3) {
   143  *        int mid = (l + h) >>> 1;
   143  *       int mid = (l + h) >>> 1;
   144  *        right = new Applyer(array, mid, h, right);
   144  *       right = new Applyer(array, mid, h, right);
   145  *        right.fork();
   145  *       right.fork();
   146  *        h = mid;
   146  *       h = mid;
   147  *     }
   147  *     }
   148  *     double sum = atLeaf(l, h);
   148  *     double sum = atLeaf(l, h);
   149  *     while (right != null) {
   149  *     while (right != null) {
   150  *        if (right.tryUnfork()) // directly calculate if not stolen
   150  *       if (right.tryUnfork()) // directly calculate if not stolen
   151  *          sum += right.atLeaf(right.lo, right.hi);
   151  *         sum += right.atLeaf(right.lo, right.hi);
   152  *       else {
   152  *       else {
   153  *          right.join();
   153  *         right.join();
   154  *          sum += right.result;
   154  *         sum += right.result;
   155  *        }
   155  *       }
   156  *        right = right.next;
   156  *       right = right.next;
   157  *      }
   157  *     }
   158  *     result = sum;
   158  *     result = sum;
   159  *   }
   159  *   }
   160  * }}</pre>
   160  * }}</pre>
   161  *
   161  *
   162  * @since 1.7
   162  * @since 1.7