private synchronized void createExecutor ( ) { if ( componentConfig == null ) { // this is a completely normal occurrence and can happen if a ThreadFactory is bound prior to // component activation... the proper thing to do is to do nothing and wait for activation return ; } if ( threadPoolController != null ) threadPoolController . deactivate ( ) ; ThreadPoolExecutor oldPool = threadPool ; poolName = ( String ) componentConfig . get ( "name" ) ; String threadGroupName = poolName + " Thread Group" ; int coreThreads = Integer . parseInt ( String . valueOf ( componentConfig . get ( "coreThreads" ) ) ) ; int maxThreads = Integer . parseInt ( String . valueOf ( componentConfig . get ( "maxThreads" ) ) ) ; if ( maxThreads <= 0 ) { maxThreads = Integer . MAX_VALUE ; } if ( coreThreads < 0 ) { coreThreads = 2 * CpuInfo . getAvailableProcessors ( ) ; } // Make sure coreThreads is not bigger than maxThreads, subject to MINIMUM_POOL_SIZE limit coreThreads = Math . max ( MINIMUM_POOL_SIZE , Math . min ( coreThreads , maxThreads ) ) ; // ... and then make sure maxThreads is not smaller than coreThreads ... maxThreads = Math . max ( coreThreads , maxThreads ) ; BlockingQueue < Runnable > workQueue = new BoundedBuffer < Runnable > ( java . lang . Runnable . class , 1000 , 1000 ) ; RejectedExecutionHandler rejectedExecutionHandler = new ExpandPolicy ( workQueue , this ) ; threadPool = new ThreadPoolExecutor ( coreThreads , maxThreads , 0 , TimeUnit . MILLISECONDS , workQueue , threadFactory != null ? threadFactory : new ThreadFactoryImpl ( poolName , threadGroupName ) , rejectedExecutionHandler ) ; threadPoolController = new ThreadPoolController ( this , threadPool ) ; if ( oldPool != null ) { softShutdown ( oldPool ) ; } }
Create a thread pool executor with the configured attributes from this component config .