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 (;;) { |
806 |
|
// Maintaining parallelism |
807 |
|
|
808 |
|
/** |
809 |
< |
* Pushes worker onto the spare stack |
809 |
> |
* Pushes worker onto the spare stack. |
810 |
|
*/ |
811 |
|
final void pushSpare(ForkJoinWorkerThread w) { |
812 |
|
int ns = (++w.spareCount << SPARE_COUNT_SHIFT) | (w.poolIndex + 1); |
1225 |
|
* use {@link #defaultForkJoinWorkerThreadFactory}. |
1226 |
|
* @param handler the handler for internal worker threads that |
1227 |
|
* terminate due to unrecoverable errors encountered while executing |
1228 |
< |
* tasks. For default value, use <code>null</code>. |
1228 |
> |
* tasks. For default value, use {@code null}. |
1229 |
|
* @param asyncMode if true, |
1230 |
|
* establishes local first-in-first-out scheduling mode for forked |
1231 |
|
* tasks that are never joined. This mode may be more appropriate |
1232 |
|
* than default locally stack-based mode in applications in which |
1233 |
|
* worker threads only process event-style asynchronous tasks. |
1234 |
< |
* For default value, use <code>false</code>. |
1234 |
> |
* For default value, use {@code false}. |
1235 |
|
* @throws IllegalArgumentException if parallelism less than or |
1236 |
|
* equal to zero, or greater than implementation limit |
1237 |
|
* @throws NullPointerException if the factory is null |
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 { |