19 |
|
import java.util.concurrent.RejectedExecutionException; |
20 |
|
import java.util.concurrent.RunnableFuture; |
21 |
|
import java.util.concurrent.TimeUnit; |
22 |
– |
import java.util.concurrent.TimeoutException; |
22 |
|
import java.util.concurrent.atomic.AtomicInteger; |
23 |
|
import java.util.concurrent.locks.LockSupport; |
24 |
|
import java.util.concurrent.locks.ReentrantLock; |
101 |
|
* daemon} mode, there is typically no need to explicitly {@link |
102 |
|
* #shutdown} such a pool upon program exit. |
103 |
|
* |
104 |
< |
* <pre> |
104 |
> |
* <pre> {@code |
105 |
|
* static final ForkJoinPool mainPool = new ForkJoinPool(); |
106 |
|
* ... |
107 |
|
* public void sort(long[] array) { |
108 |
|
* mainPool.invoke(new SortTask(array, 0, array.length)); |
109 |
< |
* } |
111 |
< |
* </pre> |
109 |
> |
* }}</pre> |
110 |
|
* |
111 |
|
* <p><b>Implementation notes</b>: This implementation restricts the |
112 |
|
* maximum number of running threads to 32767. Attempts to create |
947 |
|
int pc = parallelism; |
948 |
|
do { |
949 |
|
ForkJoinWorkerThread[] ws; ForkJoinWorkerThread w; |
950 |
< |
int e, ac, tc, rc, i; |
950 |
> |
int e, ac, tc, i; |
951 |
|
long c = ctl; |
952 |
|
int u = (int)(c >>> 32); |
953 |
|
if ((e = (int)c) < 0) { |
987 |
|
} |
988 |
|
|
989 |
|
/** |
990 |
< |
* Decrements blockedCount and increments active count |
990 |
> |
* Decrements blockedCount and increments active count. |
991 |
|
*/ |
992 |
|
private void postBlock() { |
993 |
|
long c; |
1005 |
|
* @param joinMe the task |
1006 |
|
*/ |
1007 |
|
final void tryAwaitJoin(ForkJoinTask<?> joinMe) { |
1010 |
– |
int s; |
1008 |
|
Thread.interrupted(); // clear interrupts before checking termination |
1009 |
|
if (joinMe.status >= 0) { |
1010 |
|
if (tryPreBlock()) { |
1018 |
|
|
1019 |
|
/** |
1020 |
|
* Possibly blocks the given worker waiting for joinMe to |
1021 |
< |
* complete or timeout |
1021 |
> |
* complete or timeout. |
1022 |
|
* |
1023 |
|
* @param joinMe the task |
1024 |
|
* @param millis the wait time for underlying Object.wait |
1054 |
|
} |
1055 |
|
|
1056 |
|
/** |
1057 |
< |
* If necessary, compensates for blocker, and blocks |
1057 |
> |
* If necessary, compensates for blocker, and blocks. |
1058 |
|
*/ |
1059 |
|
private void awaitBlocker(ManagedBlocker blocker) |
1060 |
|
throws InterruptedException { |
2115 |
|
modifyThreadPermission = new RuntimePermission("modifyThread"); |
2116 |
|
defaultForkJoinWorkerThreadFactory = |
2117 |
|
new DefaultForkJoinWorkerThreadFactory(); |
2121 |
– |
int s; |
2118 |
|
try { |
2119 |
|
UNSAFE = getUnsafe(); |
2120 |
|
Class<?> k = ForkJoinPool.class; |
2130 |
|
(k.getDeclaredField("scanGuard")); |
2131 |
|
nextWorkerNumberOffset = UNSAFE.objectFieldOffset |
2132 |
|
(k.getDeclaredField("nextWorkerNumber")); |
2137 |
– |
Class<?> a = ForkJoinTask[].class; |
2138 |
– |
ABASE = UNSAFE.arrayBaseOffset(a); |
2139 |
– |
s = UNSAFE.arrayIndexScale(a); |
2133 |
|
} catch (Exception e) { |
2134 |
|
throw new Error(e); |
2135 |
|
} |
2136 |
+ |
Class<?> a = ForkJoinTask[].class; |
2137 |
+ |
ABASE = UNSAFE.arrayBaseOffset(a); |
2138 |
+ |
int s = UNSAFE.arrayIndexScale(a); |
2139 |
|
if ((s & (s-1)) != 0) |
2140 |
|
throw new Error("data type scale not a power of two"); |
2141 |
|
ASHIFT = 31 - Integer.numberOfLeadingZeros(s); |