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

Comparing jsr166/src/jdk8/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.2 by jsr166, Sun Jun 4 23:04:03 2017 UTC vs.
Revision 1.3 by jsr166, Mon Jul 24 15:09:05 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 1448 | Line 1457 | public class ThreadPoolExecutor extends
1457      /**
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      protected void finalize() {
1465 <        shutdown();
1465 >        SecurityManager sm = System.getSecurityManager();
1466 >        if (sm == null || acc == null) {
1467 >            shutdown();
1468 >        } else {
1469 >            PrivilegedAction<Void> pa = () -> { shutdown(); return null; };
1470 >            AccessController.doPrivileged(pa, acc);
1471 >        }
1472      }
1473  
1474      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines