private ExecutorService getSharedES ( ) { synchronized ( this . getClass ( ) ) { if ( sharedES != null ) { return sharedES ; } sharedES = new ThreadPoolExecutor ( maxAsyncThreads / 10 , maxAsyncThreads , 60L , TimeUnit . SECONDS , new ArrayBlockingQueue < Runnable > ( maxAsyncQueueSize ) , new ThreadFactory ( ) { private final AtomicInteger threadNumber = new AtomicInteger ( 1 ) ; @ Override public Thread newThread ( Runnable task ) { Thread thread = new Thread ( task , "MWSClient-" + threadNumber . getAndIncrement ( ) ) ; thread . setDaemon ( true ) ; thread . setPriority ( Thread . NORM_PRIORITY ) ; return thread ; } } , new RejectedExecutionHandler ( ) { @ Override public void rejectedExecution ( Runnable task , ThreadPoolExecutor executor ) { if ( ! executor . isShutdown ( ) ) { log . warn ( "MWSClient async queue full, running on calling thread." ) ; task . run ( ) ; } else { throw new RejectedExecutionException ( ) ; } } } ) ; return sharedES ; } }
Get the shared executor service that is used by async calls if no executor is supplied .