Java 类com.zaxxer.hikari.util.ConcurrentBag 实例源码

项目:object-pool-benchmarks    文件:ClaimRelease.java   
@Override
public void preparePool() throws Exception {
  bag = new ConcurrentBag<>(new ConcurrentBag.IBagStateListener() {
    @Override
    public Future<Boolean> addBagItem() {
      return null;
    }
  });
  for (int i = 0; i < poolSize; i++) {
    Costs.expendAllocation();
    bag.add(new ConcurrentBag.IConcurrentBagEntry() {
      final AtomicInteger state = new AtomicInteger(ConcurrentBag.IConcurrentBagEntry.STATE_NOT_IN_USE);

      @Override
      public boolean compareAndSet(int from, int to) {
        return state.compareAndSet(from, to);
      }

      @Override
      public int getState() {
        return state.get();
      }
    });
  }
}
项目:org.ops4j.pax.transx    文件:GenericConnectionManager.java   
Pool(SubjectCRIKey key) {
    this.key = key;
    this.bag = new ConcurrentBag<>(this::addNewConnection);
}
项目:HikariCP    文件:HikariPool.java   
/**
 * Construct a HikariPool with the specified configuration.
 *
 * @param config a HikariConfig instance
 */
public HikariPool(final HikariConfig config)
 {
   this.config = config;

   this.poolElf = new PoolElf(config);
   this.dataSource = poolElf.initializeDataSource();

   this.poolName = config.getPoolName();
   this.connectionBag = new ConcurrentBag<>(this);
   this.totalConnections = new AtomicInteger();
   this.connectionTimeout = config.getConnectionTimeout();
   this.lastConnectionFailure = new AtomicReference<>();
   this.suspendResumeLock = config.isAllowPoolSuspension() ? new SuspendResumeLock(true) : SuspendResumeLock.FAUX_LOCK;

   this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection filler (pool " + poolName + ")", config.getThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
   this.closeConnectionExecutor = createThreadPoolExecutor(4, "Hikari connection closer (pool " + poolName + ")", config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());

   if (config.getScheduledExecutorService() == null) {
      ThreadFactory threadFactory = config.getThreadFactory() != null ? config.getThreadFactory() : new DefaultThreadFactory("Hikari housekeeper (pool " + poolName + ")", true);
      this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
      this.houseKeepingExecutorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
      this.houseKeepingExecutorService.setRemoveOnCancelPolicy(true);
   }
   else {
      this.houseKeepingExecutorService = config.getScheduledExecutorService();
   }

   this.houseKeepingExecutorService.scheduleAtFixedRate(new HouseKeeper(), HOUSEKEEPING_PERIOD_MS, HOUSEKEEPING_PERIOD_MS, TimeUnit.MILLISECONDS);

   this.leakTask = new LeakTask(config.getLeakDetectionThreshold(), houseKeepingExecutorService);

   if (config.getMetricsTrackerFactory() != null) {
      setMetricsTrackerFactory(config.getMetricsTrackerFactory());
   }
   else {
      setMetricRegistry(config.getMetricRegistry());
   }

   setHealthCheckRegistry(config.getHealthCheckRegistry());

   poolElf.registerMBeans(this);

   PropertyElf.flushCaches();

   initializeConnections();
}
项目:object-pool-benchmarks    文件:ClaimRelease.java   
@Override
public Object claim() throws Exception {
  final ConcurrentBag.IConcurrentBagEntry borrow = bag.borrow(1, TimeUnit.DAYS);
  Costs.expendValidation();
  return borrow;
}
项目:object-pool-benchmarks    文件:ClaimRelease.java   
@Override
public void release(Object obj) throws Exception {
  bag.requite((ConcurrentBag.IConcurrentBagEntry) obj);
}