43 |
|
* Full nonpublic constructor. |
44 |
|
*/ |
45 |
|
ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool, |
46 |
< |
boolean useSystemClassLoader, boolean isInnocuous) { |
47 |
< |
super(group, null, pool.nextWorkerThreadName(), 0L, !isInnocuous); |
46 |
> |
boolean useSystemClassLoader, |
47 |
> |
boolean clearThreadLocals) { |
48 |
> |
super(group, null, pool.nextWorkerThreadName(), 0L, !clearThreadLocals); |
49 |
|
UncaughtExceptionHandler handler = (this.pool = pool).ueh; |
50 |
|
this.workQueue = new ForkJoinPool.WorkQueue(this, 0); |
51 |
+ |
if (clearThreadLocals) |
52 |
+ |
workQueue.setClearThreadLocals(); |
53 |
|
super.setDaemon(true); |
54 |
|
if (handler != null) |
55 |
|
super.setUncaughtExceptionHandler(handler); |
61 |
|
* Creates a ForkJoinWorkerThread operating in the given thread group and |
62 |
|
* pool, and with the given policy for preserving ThreadLocals. |
63 |
|
* |
64 |
< |
* @param group if non-null, the thread group for this thread |
64 |
> |
* @param group if non-null, the thread group for this |
65 |
> |
* thread. Otherwise, the thread group is chosen by the security |
66 |
> |
* manager if present, else set to the current thread's thread |
67 |
> |
* group. |
68 |
|
* @param pool the pool this thread works in |
69 |
|
* @param preserveThreadLocals if true, always preserve the values of |
70 |
|
* ThreadLocal variables across tasks; otherwise they may be cleared. |
164 |
|
/** |
165 |
|
* A worker thread that has no permissions, is not a member of any |
166 |
|
* user-defined ThreadGroup, uses the system class loader as |
167 |
< |
* thread context class loader, and erases all ThreadLocals after |
167 |
> |
* thread context class loader, and clears all ThreadLocals after |
168 |
|
* running each top-level task. |
169 |
|
*/ |
170 |
|
static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread { |
178 |
|
|
179 |
|
@Override @SuppressWarnings("removal") |
180 |
|
protected void onStart() { |
175 |
– |
ForkJoinPool.WorkQueue w = workQueue; |
176 |
– |
if (w != null) |
177 |
– |
w.setInnocuous(); |
181 |
|
Thread t = Thread.currentThread(); |
182 |
|
ThreadLocalRandom.setInheritedAccessControlContext(t, innocuousACC); |
183 |
|
} |