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

Comparing jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.179 by jsr166, Tue Sep 12 17:57:16 2017 UTC vs.
Revision 1.180 by jsr166, Tue Sep 12 21:38:35 2017 UTC

# Line 354 | Line 354 | public class ThreadPoolExecutor extends
354       */
355      private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));
356      private static final int COUNT_BITS = Integer.SIZE - 3;
357 <    private static final int CAPACITY   = (1 << COUNT_BITS) - 1;
357 >    private static final int COUNT_MASK = (1 << COUNT_BITS) - 1;
358  
359      // runState is stored in the high-order bits
360      private static final int RUNNING    = -1 << COUNT_BITS;
# Line 364 | Line 364 | public class ThreadPoolExecutor extends
364      private static final int TERMINATED =  3 << COUNT_BITS;
365  
366      // Packing and unpacking ctl
367 <    private static int runStateOf(int c)     { return c & ~CAPACITY; }
368 <    private static int workerCountOf(int c)  { return c & CAPACITY; }
367 >    private static int runStateOf(int c)     { return c & ~COUNT_MASK; }
368 >    private static int workerCountOf(int c)  { return c & COUNT_MASK; }
369      private static int ctlOf(int rs, int wc) { return rs | wc; }
370  
371      /*
# Line 509 | Line 509 | public class ThreadPoolExecutor extends
509       * Core pool size is the minimum number of workers to keep alive
510       * (and not allow to time out etc) unless allowCoreThreadTimeOut
511       * is set, in which case the minimum is zero.
512 +     *
513 +     * Since the worker count is actually stored in COUNT_BITS bits,
514 +     * the effective limit is {@code corePoolSize & COUNT_MASK}.
515       */
516      private volatile int corePoolSize;
517  
518      /**
519 <     * Maximum pool size. Note that the actual maximum is internally
520 <     * bounded by CAPACITY.
519 >     * Maximum pool size.
520 >     *
521 >     * Since the worker count is actually stored in COUNT_BITS bits,
522 >     * the effective limit is {@code maximumPoolSize & COUNT_MASK}.
523       */
524      private volatile int maximumPoolSize;
525  
# Line 876 | Line 881 | public class ThreadPoolExecutor extends
881                  return false;
882  
883              for (;;) {
884 <                int wc = workerCountOf(c);
885 <                if (wc >= CAPACITY ||
881 <                    wc >= (core ? corePoolSize : maximumPoolSize))
884 >                if (workerCountOf(c)
885 >                    >= ((core ? corePoolSize : maximumPoolSize) & COUNT_MASK))
886                      return false;
887                  if (compareAndIncrementWorkerCount(c))
888                      break retry;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines