/** * Tries to create and start one worker if fewer than target * parallelism level exist. Adjusts counts etc on failure. */ private void tryAddWorker() { long c; int u, e; while ((u = (int)((c = ctl) >>> 32)) < 0 && (u & SHORT_SIGN) != 0 && (e = (int)c) >= 0) { long nc = ((long)(((u + UTC_UNIT) & UTC_MASK) | ((u + UAC_UNIT) & UAC_MASK)) << 32) | (long)e; if (U.compareAndSwapLong(this, CTL, c, nc)) { ForkJoinWorkerThreadFactory fac; Throwable ex = null; ForkJoinWorkerThread wt = null; try { if ((fac = factory) != null && (wt = fac.newThread(this)) != null) { wt.start(); break; } } catch (Throwable rex) { ex = rex; } deregisterWorker(wt, ex); break; } } }
ex = rex; deregisterWorker(wt, ex); // clean up and return false
/** * This method is required to be public, but should never be * called explicitly. It performs the main run loop to execute * {@link ForkJoinTask}s. */ public void run() { Throwable exception = null; try { onStart(); pool.runWorker(workQueue); } catch (Throwable ex) { exception = ex; } finally { try { onTermination(exception); } catch (Throwable ex) { if (exception == null) exception = ex; } finally { pool.deregisterWorker(this, exception); } } } }