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; |
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 |
|
/* |
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 |
|
|
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; |