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; |
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. |
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; |
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 |
|
/** |