6 |
|
|
7 |
|
package jsr166y; |
8 |
|
|
9 |
– |
import java.util.concurrent.*; |
9 |
|
import java.util.ArrayList; |
10 |
|
import java.util.Arrays; |
11 |
|
import java.util.Collection; |
428 |
|
|
429 |
|
/** |
430 |
|
* The wakeup interval (in nanoseconds) for the oldest worker |
431 |
< |
* waiting for an event invokes tryShutdownUnusedWorker to shrink |
432 |
< |
* the number of workers. The exact value does not matter too |
433 |
< |
* much, but should be long enough to slowly release resources |
434 |
< |
* during long periods without use without disrupting normal use. |
431 |
> |
* waiting for an event to invoke tryShutdownUnusedWorker to |
432 |
> |
* shrink the number of workers. The exact value does not matter |
433 |
> |
* too much. It must be short enough to release resources during |
434 |
> |
* sustained periods of idleness, but not so short that threads |
435 |
> |
* are continually re-created. |
436 |
|
*/ |
437 |
|
private static final long SHRINK_RATE_NANOS = |
438 |
|
30L * 1000L * 1000L * 1000L; // 2 per minute |
604 |
|
* (rarely) necessary when other count updates lag. |
605 |
|
* |
606 |
|
* @param dr -- either zero or ONE_RUNNING |
607 |
< |
* @param dt == either zero or ONE_TOTAL |
607 |
> |
* @param dt -- either zero or ONE_TOTAL |
608 |
|
*/ |
609 |
|
private void decrementWorkerCounts(int dr, int dt) { |
610 |
|
for (;;) { |
1441 |
|
|
1442 |
|
/** |
1443 |
|
* Returns the number of worker threads that have started but not |
1444 |
< |
* yet terminated. This result returned by this method may differ |
1444 |
> |
* yet terminated. The result returned by this method may differ |
1445 |
|
* from {@link #getParallelism} when threads are created to |
1446 |
|
* maintain parallelism when others are cooperatively blocked. |
1447 |
|
* |
1842 |
|
private static final long eventCountOffset = |
1843 |
|
objectFieldOffset("eventCount", ForkJoinPool.class); |
1844 |
|
private static final long eventWaitersOffset = |
1845 |
< |
objectFieldOffset("eventWaiters",ForkJoinPool.class); |
1845 |
> |
objectFieldOffset("eventWaiters", ForkJoinPool.class); |
1846 |
|
private static final long stealCountOffset = |
1847 |
< |
objectFieldOffset("stealCount",ForkJoinPool.class); |
1847 |
> |
objectFieldOffset("stealCount", ForkJoinPool.class); |
1848 |
|
private static final long spareWaitersOffset = |
1849 |
< |
objectFieldOffset("spareWaiters",ForkJoinPool.class); |
1849 |
> |
objectFieldOffset("spareWaiters", ForkJoinPool.class); |
1850 |
|
|
1851 |
|
private static long objectFieldOffset(String field, Class<?> klazz) { |
1852 |
|
try { |