private void tryInitialize ( boolean checkTermination ) { if ( runState == 0 ) { // bootstrap by locking static field int p = config & SMASK ; int n = ( p > 1 ) ? p - 1 : 1 ; // ensure at least 2 slots n |= n >>> 1 ; // create workQueues array with size a power of two n |= n >>> 2 ; n |= n >>> 4 ; n |= n >>> 8 ; n |= n >>> 16 ; n = ( ( n + 1 ) << 1 ) & SMASK ; AuxState aux = new AuxState ( ) ; WorkQueue [ ] ws = new WorkQueue [ n ] ; synchronized ( modifyThreadPermission ) { // double-check if ( runState == 0 ) { workQueues = ws ; auxState = aux ; runState = STARTED ; } } } if ( checkTermination && runState < 0 ) { tryTerminate ( false , false ) ; // help terminate throw new RejectedExecutionException ( ) ; } }
Instantiates fields upon first submission or upon shutdown if no submissions . If checkTermination true also responds to termination by external calls submitting tasks .