< prev index next >

src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java

Print this page

 72     ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool,
 73                          boolean useSystemClassLoader, boolean isInnocuous) {
 74         super(group, null, pool.nextWorkerThreadName(), 0L);
 75         UncaughtExceptionHandler handler = (this.pool = pool).ueh;
 76         this.workQueue = new ForkJoinPool.WorkQueue(this, isInnocuous);
 77         super.setDaemon(true);
 78         if (handler != null)
 79             super.setUncaughtExceptionHandler(handler);
 80         if (useSystemClassLoader)
 81             super.setContextClassLoader(ClassLoader.getSystemClassLoader());
 82     }
 83 
 84     /**
 85      * Creates a ForkJoinWorkerThread operating in the given thread group and
 86      * pool.
 87      *
 88      * @param group if non-null, the thread group for this thread
 89      * @param pool the pool this thread works in
 90      * @throws NullPointerException if pool is null
 91      */
 92     /* TODO: protected */ ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool) {
 93         this(group, pool, false, false);
 94     }
 95 
 96     /**
 97      * Creates a ForkJoinWorkerThread operating in the given pool.
 98      *
 99      * @param pool the pool this thread works in
100      * @throws NullPointerException if pool is null
101      */
102     protected ForkJoinWorkerThread(ForkJoinPool pool) {
103         this(null, pool, false, false);
104     }
105 
106     /**
107      * Returns the pool hosting this thread.
108      *
109      * @return the pool
110      */
111     public ForkJoinPool getPool() {
112         return pool;

172                     if (exception == null)
173                         exception = ex;
174                 } finally {
175                     p.deregisterWorker(this, exception);
176                 }
177             }
178         }
179     }
180 
181     /**
182      * A worker thread that has no permissions, is not a member of any
183      * user-defined ThreadGroup, uses the system class loader as
184      * thread context class loader, and erases all ThreadLocals after
185      * running each top-level task.
186      */
187     static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
188         /** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
189         @SuppressWarnings("removal")
190         private static final ThreadGroup innocuousThreadGroup =
191             AccessController.doPrivileged(new PrivilegedAction<>() {

192                 public ThreadGroup run() {
193                     ThreadGroup group = Thread.currentThread().getThreadGroup();
194                     for (ThreadGroup p; (p = group.getParent()) != null; )
195                         group = p;
196                     return new ThreadGroup(
197                         group, "InnocuousForkJoinWorkerThreadGroup");
198                 }});
199 
200         InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
201             super(innocuousThreadGroup, pool, true, true);
202         }
203 
204         @Override // to silently fail
205         public void setUncaughtExceptionHandler(UncaughtExceptionHandler x) { }
206 
207         @Override // paranoically
208         public void setContextClassLoader(ClassLoader cl) {
209             if (cl != null && ClassLoader.getSystemClassLoader() != cl)
210                 throw new SecurityException("setContextClassLoader");
211         }

 72     ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool,
 73                          boolean useSystemClassLoader, boolean isInnocuous) {
 74         super(group, null, pool.nextWorkerThreadName(), 0L);
 75         UncaughtExceptionHandler handler = (this.pool = pool).ueh;
 76         this.workQueue = new ForkJoinPool.WorkQueue(this, isInnocuous);
 77         super.setDaemon(true);
 78         if (handler != null)
 79             super.setUncaughtExceptionHandler(handler);
 80         if (useSystemClassLoader)
 81             super.setContextClassLoader(ClassLoader.getSystemClassLoader());
 82     }
 83 
 84     /**
 85      * Creates a ForkJoinWorkerThread operating in the given thread group and
 86      * pool.
 87      *
 88      * @param group if non-null, the thread group for this thread
 89      * @param pool the pool this thread works in
 90      * @throws NullPointerException if pool is null
 91      */
 92     protected ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool) {
 93         this(group, pool, false, false);
 94     }
 95 
 96     /**
 97      * Creates a ForkJoinWorkerThread operating in the given pool.
 98      *
 99      * @param pool the pool this thread works in
100      * @throws NullPointerException if pool is null
101      */
102     protected ForkJoinWorkerThread(ForkJoinPool pool) {
103         this(null, pool, false, false);
104     }
105 
106     /**
107      * Returns the pool hosting this thread.
108      *
109      * @return the pool
110      */
111     public ForkJoinPool getPool() {
112         return pool;

172                     if (exception == null)
173                         exception = ex;
174                 } finally {
175                     p.deregisterWorker(this, exception);
176                 }
177             }
178         }
179     }
180 
181     /**
182      * A worker thread that has no permissions, is not a member of any
183      * user-defined ThreadGroup, uses the system class loader as
184      * thread context class loader, and erases all ThreadLocals after
185      * running each top-level task.
186      */
187     static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
188         /** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
189         @SuppressWarnings("removal")
190         private static final ThreadGroup innocuousThreadGroup =
191             AccessController.doPrivileged(new PrivilegedAction<>() {
192                 @SuppressWarnings("deprecation")
193                 public ThreadGroup run() {
194                     ThreadGroup group = Thread.currentThread().getThreadGroup();
195                     for (ThreadGroup p; (p = group.getParent()) != null; )
196                         group = p;
197                     return new ThreadGroup(
198                         group, "InnocuousForkJoinWorkerThreadGroup");
199                 }});
200 
201         InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
202             super(innocuousThreadGroup, pool, true, true);
203         }
204 
205         @Override // to silently fail
206         public void setUncaughtExceptionHandler(UncaughtExceptionHandler x) { }
207 
208         @Override // paranoically
209         public void setContextClassLoader(ClassLoader cl) {
210             if (cl != null && ClassLoader.getSystemClassLoader() != cl)
211                 throw new SecurityException("setContextClassLoader");
212         }
< prev index next >