1932 |
|
* @param task the task to join |
1933 |
|
* @param mode if shared, exit upon completing any task |
1934 |
|
* if all workers are active |
1935 |
– |
* |
1935 |
|
*/ |
1936 |
|
private int helpComplete(ForkJoinTask<?> task, int mode) { |
1937 |
|
WorkQueue[] ws; WorkQueue q; int m, n, s, u; |
2555 |
|
* ongoing processing are automatically terminated upon program |
2556 |
|
* {@link System#exit}. Any program that relies on asynchronous |
2557 |
|
* task processing to complete before program termination should |
2558 |
< |
* invoke {@link #quiesceCommonPool}, or the timeout-based {@code |
2559 |
< |
* commonPool().}{@link #awaitQuiescence}, before exit. |
2558 |
> |
* invoke {@code commonPool().}{@link #awaitQuiescence}, before |
2559 |
> |
* exit. |
2560 |
|
* |
2561 |
|
* @return the common pool instance |
2562 |
+ |
* @since 1.8 |
2563 |
|
*/ |
2564 |
|
public static ForkJoinPool commonPool() { |
2565 |
|
// assert common != null : "static init error"; |
2742 |
|
* Returns the targeted parallelism level of the common pool. |
2743 |
|
* |
2744 |
|
* @return the targeted parallelism level of the common pool |
2745 |
+ |
* @since 1.8 |
2746 |
|
*/ |
2747 |
|
public static int getCommonPoolParallelism() { |
2748 |
|
return commonParallelism; |
3003 |
|
* Possibly initiates an orderly shutdown in which previously |
3004 |
|
* submitted tasks are executed, but no new tasks will be |
3005 |
|
* accepted. Invocation has no effect on execution state if this |
3006 |
< |
* is the {@link #commonPool}, and no additional effect if |
3006 |
> |
* is the {@link #commonPool()}, and no additional effect if |
3007 |
|
* already shut down. Tasks that are in the process of being |
3008 |
|
* submitted concurrently during the course of this method may or |
3009 |
|
* may not be rejected. |
3021 |
|
/** |
3022 |
|
* Possibly attempts to cancel and/or stop all tasks, and reject |
3023 |
|
* all subsequently submitted tasks. Invocation has no effect on |
3024 |
< |
* execution state if this is the {@link #commonPool}, and no |
3024 |
> |
* execution state if this is the {@link #commonPool()}, and no |
3025 |
|
* additional effect if already shut down. Otherwise, tasks that |
3026 |
|
* are in the process of being submitted or executed concurrently |
3027 |
|
* during the course of this method may or may not be |
3173 |
|
* Waits and/or attempts to assist performing tasks indefinitely |
3174 |
|
* until the {@link #commonPool()} {@link #isQuiescent} |
3175 |
|
*/ |
3176 |
< |
public static void quiesceCommonPool() { |
3176 |
> |
static void quiesceCommonPool() { |
3177 |
|
common.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS); |
3178 |
|
} |
3179 |
|
|
3410 |
|
private static sun.misc.Unsafe getUnsafe() { |
3411 |
|
try { |
3412 |
|
return sun.misc.Unsafe.getUnsafe(); |
3413 |
< |
} catch (SecurityException se) { |
3414 |
< |
try { |
3415 |
< |
return java.security.AccessController.doPrivileged |
3416 |
< |
(new java.security |
3417 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3418 |
< |
public sun.misc.Unsafe run() throws Exception { |
3419 |
< |
java.lang.reflect.Field f = sun.misc |
3420 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
3421 |
< |
f.setAccessible(true); |
3422 |
< |
return (sun.misc.Unsafe) f.get(null); |
3423 |
< |
}}); |
3424 |
< |
} catch (java.security.PrivilegedActionException e) { |
3425 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
3426 |
< |
e.getCause()); |
3427 |
< |
} |
3413 |
> |
} catch (SecurityException tryReflectionInstead) {} |
3414 |
> |
try { |
3415 |
> |
return java.security.AccessController.doPrivileged |
3416 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3417 |
> |
public sun.misc.Unsafe run() throws Exception { |
3418 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
3419 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
3420 |
> |
f.setAccessible(true); |
3421 |
> |
Object x = f.get(null); |
3422 |
> |
if (k.isInstance(x)) |
3423 |
> |
return k.cast(x); |
3424 |
> |
} |
3425 |
> |
throw new NoSuchFieldError("the Unsafe"); |
3426 |
> |
}}); |
3427 |
> |
} catch (java.security.PrivilegedActionException e) { |
3428 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
3429 |
> |
e.getCause()); |
3430 |
|
} |
3431 |
|
} |
3429 |
– |
|
3432 |
|
} |