ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ForkJoinPool.java (file contents):
Revision 1.159 by jsr166, Mon Feb 11 17:27:45 2013 UTC vs.
Revision 1.160 by dl, Tue Feb 12 01:23:06 2013 UTC

# Line 103 | Line 103 | import java.util.concurrent.TimeUnit;
103   * parameters, but these may be controlled by setting three
104   * {@linkplain System#getProperty system properties} with prefix
105   * {@code "java.util.concurrent.ForkJoinPool.common."}:
106 < * {@code parallelism} -- an integer greater than zero,
106 > * {@code parallelism} -- a non-negative integer,
107   * {@code threadFactory} -- the class name of a
108   * {@link ForkJoinWorkerThreadFactory}, and
109   * {@code exceptionHandler} --
110   * the class name of a {@link UncaughtExceptionHandler}.
111   * Upon any error in establishing these settings, default parameters
112 < * are used.
112 > * are used. It is possible to disable or limit the use of threads in
113 > * the common pool by setting the parallelism property to zero, and/or
114 > * using a factory that may return {@code null}.
115   *
116   * <p><b>Implementation notes</b>: This implementation restricts the
117   * maximum number of running threads to 32767. Attempts to create
# Line 1051 | Line 1053 | public class ForkJoinPool extends Abstra
1053      static final ForkJoinPool common;
1054  
1055      /**
1056 <     * Common pool parallelism. Must equal common.parallelism.
1056 >     * Common pool parallelism. To allow simpler use and management
1057 >     * when common pool threads are disabled, we allow the underlying
1058 >     * common.config field to be zero, but in that case still report
1059 >     * parallelism as 1 to reflect resulting caller-runs mechanics.
1060       */
1061      static final int commonParallelism;
1062  
# Line 2359 | Line 2364 | public class ForkJoinPool extends Abstra
2364                  if (task != null)
2365                      task.doExec();
2366                  if (root.status < 0 ||
2367 <                    (u = (int)(ctl >>> 32)) >= 0 || (u >> UAC_SHIFT) >= 0)
2367 >                    (config != 0 &&
2368 >                     ((u = (int)(ctl >>> 32)) >= 0 || (u >> UAC_SHIFT) >= 0)))
2369                      break;
2370 <                if (task == null) {
2370 >               if (task == null) {
2371                      helpSignal(root, q.poolIndex);
2372                      if (root.status >= 0)
2373                          helpComplete(root, SHARED_QUEUE);
# Line 2698 | Line 2704 | public class ForkJoinPool extends Abstra
2704       * @return the targeted parallelism level of this pool
2705       */
2706      public int getParallelism() {
2707 <        return config & SMASK;
2707 >        int par = (config & SMASK);
2708 >        return (par > 0) ? par : 1;
2709      }
2710  
2711      /**
# Line 3329 | Line 3336 | public class ForkJoinPool extends Abstra
3336          common = java.security.AccessController.doPrivileged
3337              (new java.security.PrivilegedAction<ForkJoinPool>() {
3338                  public ForkJoinPool run() { return makeCommonPool(); }});
3339 <        commonParallelism = common.config; // cannot be async
3339 >        int par = common.config; // report 1 even if threads disabled
3340 >        commonParallelism = par > 0 ? par : 1;
3341      }
3342  
3343      /**
# Line 3337 | Line 3345 | public class ForkJoinPool extends Abstra
3345       * specified via system properties.
3346       */
3347      private static ForkJoinPool makeCommonPool() {
3348 <        int parallelism = 0;
3348 >        int parallelism = -1;
3349          ForkJoinWorkerThreadFactory factory
3350              = defaultForkJoinWorkerThreadFactory;
3351          UncaughtExceptionHandler handler = null;
# Line 3359 | Line 3367 | public class ForkJoinPool extends Abstra
3367          } catch (Exception ignore) {
3368          }
3369  
3370 <        if (parallelism <= 0)
3370 >        if (parallelism < 0)
3371              parallelism = Runtime.getRuntime().availableProcessors();
3372          if (parallelism > MAX_CAP)
3373              parallelism = MAX_CAP;
3366
3374          return new ForkJoinPool(parallelism, factory, handler, false,
3375                                  "ForkJoinPool.commonPool-worker-");
3376      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines