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; |
12 |
|
import java.util.Collections; |
13 |
|
import java.util.List; |
14 |
+ |
import java.util.concurrent.AbstractExecutorService; |
15 |
+ |
import java.util.concurrent.Callable; |
16 |
+ |
import java.util.concurrent.CountDownLatch; |
17 |
+ |
import java.util.concurrent.ExecutorService; |
18 |
+ |
import java.util.concurrent.Future; |
19 |
+ |
import java.util.concurrent.RejectedExecutionException; |
20 |
+ |
import java.util.concurrent.RunnableFuture; |
21 |
+ |
import java.util.concurrent.TimeUnit; |
22 |
+ |
import java.util.concurrent.TimeoutException; |
23 |
+ |
import java.util.concurrent.atomic.AtomicInteger; |
24 |
|
import java.util.concurrent.locks.LockSupport; |
25 |
|
import java.util.concurrent.locks.ReentrantLock; |
17 |
– |
import java.util.concurrent.atomic.AtomicInteger; |
18 |
– |
import java.util.concurrent.CountDownLatch; |
26 |
|
|
27 |
|
/** |
28 |
|
* An {@link ExecutorService} for running {@link ForkJoinTask}s. |
436 |
|
|
437 |
|
/** |
438 |
|
* The wakeup interval (in nanoseconds) for the oldest worker |
439 |
< |
* waiting for an event invokes tryShutdownUnusedWorker to shrink |
440 |
< |
* the number of workers. The exact value does not matter too |
441 |
< |
* much, but should be long enough to slowly release resources |
442 |
< |
* during long periods without use without disrupting normal use. |
439 |
> |
* waiting for an event to invoke tryShutdownUnusedWorker to |
440 |
> |
* shrink the number of workers. The exact value does not matter |
441 |
> |
* too much. It must be short enough to release resources during |
442 |
> |
* sustained periods of idleness, but not so short that threads |
443 |
> |
* are continually re-created. |
444 |
|
*/ |
445 |
|
private static final long SHRINK_RATE_NANOS = |
446 |
|
30L * 1000L * 1000L * 1000L; // 2 per minute |
612 |
|
* (rarely) necessary when other count updates lag. |
613 |
|
* |
614 |
|
* @param dr -- either zero or ONE_RUNNING |
615 |
< |
* @param dt == either zero or ONE_TOTAL |
615 |
> |
* @param dt -- either zero or ONE_TOTAL |
616 |
|
*/ |
617 |
|
private void decrementWorkerCounts(int dr, int dt) { |
618 |
|
for (;;) { |
1449 |
|
|
1450 |
|
/** |
1451 |
|
* Returns the number of worker threads that have started but not |
1452 |
< |
* yet terminated. This result returned by this method may differ |
1452 |
> |
* yet terminated. The result returned by this method may differ |
1453 |
|
* from {@link #getParallelism} when threads are created to |
1454 |
|
* maintain parallelism when others are cooperatively blocked. |
1455 |
|
* |
1850 |
|
private static final long eventCountOffset = |
1851 |
|
objectFieldOffset("eventCount", ForkJoinPool.class); |
1852 |
|
private static final long eventWaitersOffset = |
1853 |
< |
objectFieldOffset("eventWaiters",ForkJoinPool.class); |
1853 |
> |
objectFieldOffset("eventWaiters", ForkJoinPool.class); |
1854 |
|
private static final long stealCountOffset = |
1855 |
< |
objectFieldOffset("stealCount",ForkJoinPool.class); |
1855 |
> |
objectFieldOffset("stealCount", ForkJoinPool.class); |
1856 |
|
private static final long spareWaitersOffset = |
1857 |
< |
objectFieldOffset("spareWaiters",ForkJoinPool.class); |
1857 |
> |
objectFieldOffset("spareWaiters", ForkJoinPool.class); |
1858 |
|
|
1859 |
|
private static long objectFieldOffset(String field, Class<?> klazz) { |
1860 |
|
try { |