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

Comparing jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.174 by jsr166, Mon Apr 17 23:27:44 2017 UTC vs.
Revision 1.175 by jsr166, Mon Jul 24 14:46:20 2017 UTC

# Line 6 | Line 6
6  
7   package java.util.concurrent;
8  
9 + import java.security.AccessControlContext;
10 + import java.security.AccessController;
11 + import java.security.PrivilegedAction;
12   import java.util.ArrayList;
13   import java.util.ConcurrentModificationException;
14   import java.util.HashSet;
# Line 544 | Line 547 | public class ThreadPoolExecutor extends
547      private static final RuntimePermission shutdownPerm =
548          new RuntimePermission("modifyThread");
549  
550 +    /* The context to be used when executing the finalizer, or null. */
551 +    private final AccessControlContext acc;
552 +
553      /**
554       * Class Worker mainly maintains interrupt control state for
555       * threads running tasks, along with other minor bookkeeping.
# Line 1279 | Line 1285 | public class ThreadPoolExecutor extends
1285              throw new IllegalArgumentException();
1286          if (workQueue == null || threadFactory == null || handler == null)
1287              throw new NullPointerException();
1288 +        this.acc = System.getSecurityManager() == null ?
1289 +                null :
1290 +                AccessController.getContext();
1291          this.corePoolSize = corePoolSize;
1292          this.maximumPoolSize = maximumPoolSize;
1293          this.workQueue = workQueue;
# Line 1449 | Line 1458 | public class ThreadPoolExecutor extends
1458       * Invokes {@code shutdown} when this executor is no longer
1459       * referenced and it has no threads.
1460       *
1461 +     * <p>This method is invoked with privileges that are restricted by
1462 +     * the security context of the caller that invokes the constructor.
1463 +     *
1464       * @deprecated The {@code finalize} method has been deprecated.
1465       *     Subclasses that override {@code finalize} in order to perform cleanup
1466       *     should be modified to use alternative cleanup mechanisms and
# Line 1460 | Line 1472 | public class ThreadPoolExecutor extends
1472       */
1473      @Deprecated(since="9")
1474      protected void finalize() {
1475 <        shutdown();
1475 >        SecurityManager sm = System.getSecurityManager();
1476 >        if (sm == null || acc == null) {
1477 >            shutdown();
1478 >        } else {
1479 >            PrivilegedAction<Void> pa = () -> { shutdown(); return null; };
1480 >            AccessController.doPrivileged(pa, acc);
1481 >        }
1482      }
1483  
1484      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines