--- jsr166/src/jsr166e/ForkJoinWorkerThread.java 2012/11/14 17:20:29 1.2 +++ jsr166/src/jsr166e/ForkJoinWorkerThread.java 2012/11/21 19:54:32 1.4 @@ -25,17 +25,17 @@ public class ForkJoinWorkerThread extend * ForkJoinWorkerThreads are managed by ForkJoinPools and perform * ForkJoinTasks. For explanation, see the internal documentation * of class ForkJoinPool. + * + * This class just maintains links to its pool and WorkQueue. The + * pool field is set immediately upon construction, but the + * workQueue field is not set until a call to registerWorker + * completes. This leads to a visibility race, that is tolerated + * by requiring that the workQueue field is only accessed by the + * owning thread. */ - final ForkJoinPool.WorkQueue workQueue; // Work-stealing mechanics final ForkJoinPool pool; // the pool this thread works in - - /** - * An initial name for a newly constructed worker, used until - * onStart can establish a useful name. This removes need to - * establish a name from worker startup path. - */ - static final String provisionalName = "aForkJoinWorkerThread"; + final ForkJoinPool.WorkQueue workQueue; // work-stealing mechanics /** * Creates a ForkJoinWorkerThread operating in the given pool. @@ -44,14 +44,10 @@ public class ForkJoinWorkerThread extend * @throws NullPointerException if pool is null */ protected ForkJoinWorkerThread(ForkJoinPool pool) { - super(provisionalName); // bootstrap name - Thread.UncaughtExceptionHandler ueh = pool.ueh; - if (ueh != null) - setUncaughtExceptionHandler(ueh); - setDaemon(true); + // Use a placeholder until a useful name can be set in registerWorker + super("aForkJoinWorkerThread"); this.pool = pool; - pool.registerWorker(this.workQueue = new ForkJoinPool.WorkQueue - (pool, this, pool.localMode)); + this.workQueue = pool.registerWorker(this); } /** @@ -86,10 +82,6 @@ public class ForkJoinWorkerThread extend * processing tasks. */ protected void onStart() { - String pref; // replace bootstrap name - if (provisionalName.equals(getName()) && - (pref = pool.workerNamePrefix) != null) - setName(pref.concat(Long.toString(getId()))); } /**