예제 #1
0
 @Override
 public void start() throws CacheLoaderException {
   state = newStateMap();
   log.debugf("Async cache loader starting %s", this);
   stopped.set(false);
   lastAsyncProcessorShutsDownExecutor = false;
   super.start();
   int poolSize = asyncStoreConfig.getThreadPoolSize();
   executor =
       new ThreadPoolExecutor(
           poolSize,
           poolSize,
           0L,
           TimeUnit.MILLISECONDS,
           // note the use of poolSize+1 as maximum workingQueue together with DiscardPolicy:
           // this way when a new AsyncProcessor is started unnecessarily we discard it
           // before it takes locks to perform no work
           // this way we save memory from the executor queue, CPU, and also avoid
           // any possible RejectedExecutionException.
           new LinkedBlockingQueue<Runnable>(poolSize + 1),
           new ThreadFactory() {
             public Thread newThread(Runnable r) {
               Thread t = new Thread(r, "CoalescedAsyncStore-" + threadId.getAndIncrement());
               t.setDaemon(true);
               return t;
             }
           },
           new ThreadPoolExecutor.DiscardPolicy());
   startStoreCoordinator();
 }