예제 #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();
 }
예제 #2
0
  @Override
  public void init(CacheLoaderConfig config, Cache<?, ?> cache, StreamingMarshaller m)
      throws CacheLoaderException {
    super.init(config, cache, m);
    Configuration cacheCfg = cache != null ? cache.getConfiguration() : null;
    concurrencyLevel = cacheCfg != null ? cacheCfg.getConcurrencyLevel() : 16;
    int cacheStopTimeout = cacheCfg != null ? cacheCfg.getCacheStopTimeout() : 30000;
    Long configuredAsyncStopTimeout = asyncStoreConfig.getShutdownTimeout();
    cacheName = cacheCfg != null ? cacheCfg.getName() : null;

    // Async store shutdown timeout cannot be bigger than
    // the overall cache stop timeout, so limit it accordingly.
    if (configuredAsyncStopTimeout >= cacheStopTimeout) {
      shutdownTimeout = Math.round(cacheStopTimeout * 0.90);
      log.asyncStoreShutdownTimeoutTooHigh(
          configuredAsyncStopTimeout, cacheStopTimeout, shutdownTimeout);
    } else {
      shutdownTimeout = configuredAsyncStopTimeout;
    }

    lockContainer = new ReleaseAllLockContainer(concurrencyLevel);
    transactions =
        new ConcurrentHashMap<GlobalTransaction, List<? extends Modification>>(
            64, 0.75f, concurrencyLevel);
  }
예제 #3
0
 private void acquireLock(Lock lock) {
   try {
     if (!lock.tryLock(asyncStoreConfig.getFlushLockTimeout(), TimeUnit.MILLISECONDS))
       throw new CacheException("Unable to acquire lock on update map");
   } catch (InterruptedException ie) {
     // restore interrupted status
     Thread.currentThread().interrupt();
   }
 }