ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ForkJoinPool.java (file contents):
Revision 1.409 by dl, Fri Apr 29 17:00:36 2022 UTC vs.
Revision 1.410 by dl, Fri May 6 16:03:05 2022 UTC

# Line 211 | Line 211 | public class ForkJoinPool extends Abstra
211       * reflecting the presence or absence of other contextual sync
212       * provided by atomic and/or volatile accesses. Some methods (or
213       * their primary loops) begin with an acquire fence or
214 <     * otherwise-unnecessary valatile read that amounts to an
214 >     * otherwise-unnecessary volatile read that amounts to an
215       * acquiring read of "this" to cover all fields (which is
216       * sometimes stronger than necessary, but less brittle). Some
217       * constructions are intentionally racy because they use read
# Line 309 | Line 309 | public class ForkJoinPool extends Abstra
309       * available to try, and the presence or nature of screening steps
310       * when only some kinds of tasks can be taken. When alternatives
311       * (or failing) is an option, they uniformly give up after
312 <     * boundeed numbers of stalls and/or CAS failures, which reduces
312 >     * bounded numbers of stalls and/or CAS failures, which reduces
313       * contention when too many workers are polling too few tasks.
314       * Overall, in the aggregate, we ensure probabilistic
315       * non-blockingness of work-stealing at least until checking
# Line 443 | Line 443 | public class ForkJoinPool extends Abstra
443       *
444       * WorkQueue field "phase" is used by both workers and the pool to
445       * manage and track whether a worker is unsignalled (possibly
446 <     * blocked waiting for a signal), convienently using the sign bit
446 >     * blocked waiting for a signal), conveniently using the sign bit
447       * to check.  When a worker is enqueued its phase field is set
448       * negative. Note that phase field updates lag queue CAS releases;
449       * seeing a negative phase does not guarantee that the worker is
# Line 690 | Line 690 | public class ForkJoinPool extends Abstra
690       * overridden by system properties, we use workers of subclass
691       * InnocuousForkJoinWorkerThread when there is a SecurityManager
692       * present. These workers have no permissions set, do not belong
693 <     * to any user-defined ThreadGroup, and erase all ThreadLocals
693 >     * to any user-defined ThreadGroup, and clear all ThreadLocals
694       * after executing any top-level task.  The associated mechanics
695       * may be JVM-dependent and must access particular Thread class
696       * fields to achieve this effect.
# Line 854 | Line 854 | public class ForkJoinPool extends Abstra
854      // {pool, workQueue}.config bits
855      static final int FIFO         = 1 << 16;       // fifo queue or access mode
856      static final int SRC          = 1 << 17;       // set when stealable
857 <    static final int INNOCUOUS    = 1 << 18;       // set for Innocuous workers
857 >    static final int CLEAR_TLS    = 1 << 18;       // set for Innocuous workers
858      static final int TRIMMED      = 1 << 19;       // timed out while idle
859      static final int ISCOMMON     = 1 << 20;       // set for common pool
860      static final int PRESET_SIZE  = 1 << 21;       // size was set by property
# Line 1284 | Line 1284 | public class ForkJoinPool extends Abstra
1284              }
1285              nsteals += nstolen;
1286              source = 0;
1287 <            if ((cfg & INNOCUOUS) != 0)
1287 >            if ((cfg & CLEAR_TLS) != 0)
1288                  ThreadLocalRandom.eraseThreadLocals(Thread.currentThread());
1289          }
1290  
# Line 1420 | Line 1420 | public class ForkJoinPool extends Abstra
1420          }
1421  
1422          /**
1423 <         * Callback from InnocuousForkJoinWorkerThread.onStart
1423 >         * Called in constructors if ThreadLocals not preserved
1424           */
1425 <        final void setInnocuous() {
1426 <            config |= INNOCUOUS;
1425 >        final void setClearThreadLocals() {
1426 >            config |= CLEAR_TLS;
1427          }
1428  
1429          static {
# Line 2253 | Line 2253 | public class ForkJoinPool extends Abstra
2253       * @param interruptible true if return on interrupt
2254       * @return positive if quiescent, negative if interrupted, else 0
2255       */
2256 <    final static int helpQuiescePool(ForkJoinPool pool, long nanos,
2256 >    static final int helpQuiescePool(ForkJoinPool pool, long nanos,
2257                                       boolean interruptible) {
2258          Thread t; ForkJoinPool p; ForkJoinWorkerThread wt;
2259          if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread &&
# Line 2895 | Line 2895 | public class ForkJoinPool extends Abstra
2895       * @return the previous parallelism level.
2896       * @throws IllegalArgumentException if size is less than 1 or
2897       *         greater than the maximum supported by this pool.
2898 <     * @throws IllegalStateException if this is the{@link #commonPool()} and
2899 <     *         parallelism level was set by System property
2900 <     *         {@systemProperty java.util.concurrent.ForkJoinPool.common.parallelism}.
2898 >     * @throws UnsupportedOperationException this is the{@link
2899 >     *         #commonPool()} and parallelism level was set by System
2900 >     *         property {@systemProperty
2901 >     *         java.util.concurrent.ForkJoinPool.common.parallelism}.
2902       * @throws SecurityException if a security manager exists and
2903       *         the caller is not permitted to modify threads
2904       *         because it does not hold {@link
# Line 2908 | Line 2909 | public class ForkJoinPool extends Abstra
2909          if (size < 1 || size > MAX_CAP)
2910              throw new IllegalArgumentException();
2911          if ((config & PRESET_SIZE) != 0)
2912 <            throw new IllegalStateException("Cannot override System property");
2912 >            throw new UnsupportedOperationException("Cannot override System property");
2913          checkPermission();
2914          return getAndSetParallelism(size);
2915      }
# Line 3499 | Line 3500 | public class ForkJoinPool extends Abstra
3500      }
3501  
3502      /**
3503 +     * Unless this is the {@link #commonPool()}, initiates an orderly
3504 +     * shutdown in which previously submitted tasks are executed, but
3505 +     * no new tasks will be accepted, and waits until all tasks have
3506 +     * completed execution and the executor has terminated.
3507 +     *
3508 +     * <p> If already terminated, or this is the {@link
3509 +     * #commonPool()}, this method has no effect on execution, and
3510 +     * does not wait. Otherwise, if interrupted while waiting, this
3511 +     * method stops all executing tasks as if by invoking {@link
3512 +     * #shutdownNow()}. It then continues to wait until all actively
3513 +     * executing tasks have completed. Tasks that were awaiting
3514 +     * execution are not executed. The interrupt status will be
3515 +     * re-asserted before this method returns.
3516 +     *
3517 +     * @throws SecurityException if a security manager exists and
3518 +     *         shutting down this ExecutorService may manipulate
3519 +     *         threads that the caller is not permitted to modify
3520 +     *         because it does not hold {@link
3521 +     *         java.lang.RuntimePermission}{@code ("modifyThread")},
3522 +     *         or the security manager's {@code checkAccess} method
3523 +     *         denies access.
3524 +     * @since 19
3525 +     */
3526 +    @Override
3527 +    public void close() {
3528 +        if ((config & ISCOMMON) == 0) {
3529 +            boolean terminated = tryTerminate(false, false);
3530 +            if (!terminated) {
3531 +                shutdown();
3532 +                boolean interrupted = false;
3533 +                while (!terminated) {
3534 +                    try {
3535 +                        terminated = awaitTermination(1L, TimeUnit.DAYS);
3536 +                    } catch (InterruptedException e) {
3537 +                        if (!interrupted) {
3538 +                            shutdownNow();
3539 +                            interrupted = true;
3540 +                        }
3541 +                    }
3542 +                }
3543 +                if (interrupted) {
3544 +                    Thread.currentThread().interrupt();
3545 +                }
3546 +            }
3547 +        }
3548 +    }
3549 +
3550 +    /**
3551       * Interface for extending managed parallelism for tasks running
3552       * in {@link ForkJoinPool}s.
3553       *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines