< prev index next >

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

Print this page




  62      * ForkJoinTasks. For explanation, see the internal documentation
  63      * of class ForkJoinPool.
  64      *
  65      * This class just maintains links to its pool and WorkQueue.  The
  66      * pool field is set immediately upon construction, but the
  67      * workQueue field is not set until a call to registerWorker
  68      * completes. This leads to a visibility race, that is tolerated
  69      * by requiring that the workQueue field is only accessed by the
  70      * owning thread.
  71      *
  72      * Support for (non-public) subclass InnocuousForkJoinWorkerThread
  73      * requires that we break quite a lot of encapsulation (via helper
  74      * methods in ThreadLocalRandom) both here and in the subclass to
  75      * access and set Thread fields.
  76      */
  77 
  78     final ForkJoinPool pool;                // the pool this thread works in
  79     final ForkJoinPool.WorkQueue workQueue; // work-stealing mechanics
  80 
  81     /**
  82      * Creates a ForkJoinWorkerThread operating in the given pool.

  83      *

  84      * @param pool the pool this thread works in
  85      * @throws NullPointerException if pool is null
  86      */
  87     protected ForkJoinWorkerThread(ForkJoinPool pool) {
  88         // Use a placeholder until a useful name can be set in registerWorker
  89         super("aForkJoinWorkerThread");
  90         this.pool = pool;
  91         this.workQueue = pool.registerWorker(this);










  92     }
  93 
  94     /**
  95      * Version for use by the default pool.  Supports setting the
  96      * context class loader.  This is a separate constructor to avoid
  97      * affecting the protected constructor.
  98      */
  99     ForkJoinWorkerThread(ForkJoinPool pool, ClassLoader ccl) {
 100         super("aForkJoinWorkerThread");
 101         super.setContextClassLoader(ccl);
 102         this.pool = pool;
 103         this.workQueue = pool.registerWorker(this);
 104     }
 105 
 106     /**
 107      * Version for InnocuousForkJoinWorkerThread.
 108      */
 109     ForkJoinWorkerThread(ForkJoinPool pool,
 110                          ClassLoader ccl,
 111                          ThreadGroup threadGroup,




  62      * ForkJoinTasks. For explanation, see the internal documentation
  63      * of class ForkJoinPool.
  64      *
  65      * This class just maintains links to its pool and WorkQueue.  The
  66      * pool field is set immediately upon construction, but the
  67      * workQueue field is not set until a call to registerWorker
  68      * completes. This leads to a visibility race, that is tolerated
  69      * by requiring that the workQueue field is only accessed by the
  70      * owning thread.
  71      *
  72      * Support for (non-public) subclass InnocuousForkJoinWorkerThread
  73      * requires that we break quite a lot of encapsulation (via helper
  74      * methods in ThreadLocalRandom) both here and in the subclass to
  75      * access and set Thread fields.
  76      */
  77 
  78     final ForkJoinPool pool;                // the pool this thread works in
  79     final ForkJoinPool.WorkQueue workQueue; // work-stealing mechanics
  80 
  81     /**
  82      * Creates a ForkJoinWorkerThread operating in the given thread group and
  83      * pool.
  84      *
  85      * @param group thread group, can be null
  86      * @param pool the pool this thread works in
  87      * @throws NullPointerException if pool is null
  88      */
  89     protected ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool) {
  90         // Use a placeholder until a useful name can be set in registerWorker
  91         super(group, "aForkJoinWorkerThread");
  92         this.pool = pool;
  93         this.workQueue = pool.registerWorker(this);
  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);
 104     }
 105 
 106     /**
 107      * Version for use by the default pool.  Supports setting the
 108      * context class loader.  This is a separate constructor to avoid
 109      * affecting the protected constructor.
 110      */
 111     ForkJoinWorkerThread(ForkJoinPool pool, ClassLoader ccl) {
 112         super("aForkJoinWorkerThread");
 113         super.setContextClassLoader(ccl);
 114         this.pool = pool;
 115         this.workQueue = pool.registerWorker(this);
 116     }
 117 
 118     /**
 119      * Version for InnocuousForkJoinWorkerThread.
 120      */
 121     ForkJoinWorkerThread(ForkJoinPool pool,
 122                          ClassLoader ccl,
 123                          ThreadGroup threadGroup,


< prev index next >