List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxTotal
public void setMaxTotal(int maxTotal)
From source file:com.axibase.tsd.TestUtil.java
public static HttpClientManager buildHttpClientManager() { // Use -Daxibase.tsd.api.client.properties=<filename> to change default properties file name ClientConfigurationFactory configurationFactory = ClientConfigurationFactory.createInstance(); ClientConfiguration clientConfiguration = configurationFactory.createClientConfiguration(); HttpClientManager httpClientManager = new HttpClientManager(); httpClientManager.setClientConfiguration(clientConfiguration); GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig(); objectPoolConfig.setMaxTotal(100); objectPoolConfig.setMaxIdle(100);// w ww. j a v a 2s . c o m httpClientManager.setObjectPoolConfig(objectPoolConfig); httpClientManager.setBorrowMaxWaitMillis(10000); return httpClientManager; }
From source file:me.smoe.adar.pool.commonpool.CommonPool.java
private static GenericObjectPoolConfig buildPoolConfig(int corePoolSize, int maxPoolSize, int keepAliveTime) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxIdle(corePoolSize);/*from w w w .ja v a 2s. c o m*/ config.setMaxTotal(maxPoolSize); config.setMaxWaitMillis(keepAliveTime); return config; }
From source file:net.greghaines.jesque.utils.PoolUtils.java
/** * @return a GenericObjectPoolConfig configured with: maxActive=-1, * maxIdle=10, minIdle=1, testOnBorrow=true, * blockWhenExhausted=false//w w w . ja v a 2 s . co m */ public static GenericObjectPoolConfig getDefaultPoolConfig() { final GenericObjectPoolConfig cfg = new GenericObjectPoolConfig(); cfg.setMaxTotal(-1); // Infinite cfg.setMaxIdle(10); cfg.setMinIdle(1); cfg.setTestOnBorrow(true); cfg.setBlockWhenExhausted(false); return cfg; }
From source file:edumsg.core.PostgresConnection.java
public static void initSource() { try {// www . j av a 2 s . c o m try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, "Error loading Postgres driver: " + ex.getMessage(), ex); } try { readConfFile(); } catch (Exception e) { e.printStackTrace(); } Properties props = new Properties(); // System.out.println(DB_USERNAME); props.setProperty("user", DB_USERNAME); props.setProperty("password", DB_PASSWORD); props.setProperty("initialSize", DB_INIT_CONNECTIONS); props.setProperty("maxActive", DB_MAX_CONNECTIONS); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(DB_URL, props); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); poolableConnectionFactory.setPoolStatements(true); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxIdle(Integer.parseInt(DB_INIT_CONNECTIONS)); poolConfig.setMaxTotal(Integer.parseInt(DB_MAX_CONNECTIONS)); ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig); poolableConnectionFactory.setPool(connectionPool); Class.forName("org.apache.commons.dbcp2.PoolingDriver"); dbDriver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); dbDriver.registerPool(DB_NAME, connectionPool); dataSource = new PoolingDataSource<>(connectionPool); } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Got error initializing data source: " + ex.getMessage(), ex); } }
From source file:com.yahoo.athenz.common.server.db.DataSourceFactory.java
public static GenericObjectPoolConfig setupPoolConfig() { // setup config vars for the object pool // ie. min and max idle instances, and max total instances of arbitrary objects GenericObjectPoolConfig config = new GenericObjectPoolConfig(); // The maximum number of active connections that can be allocated from // this pool at the same time, or negative for no limit. Default: 8 config.setMaxTotal( retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL)); if (config.getMaxTotal() == 0) { config.setMaxTotal(-1); // -1 means no limit }/*from w w w .j a va 2 s .c o m*/ // The maximum number of connections that can remain idle in the pool, // without extra ones being released, or negative for no limit. Default 8 config.setMaxIdle( retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE)); if (config.getMaxIdle() == 0) { config.setMaxIdle(-1); // -1 means no limit } // The minimum number of connections that can remain idle in the pool, // without extra ones being created, or zero to create none. Default 0 config.setMinIdle( retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE)); // The maximum number of milliseconds that the pool will wait (when // there are no available connections) for a connection to be returned // before throwing an exception, or -1 to wait indefinitely. Default -1 config.setMaxWaitMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_WAIT, GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); // setup the configuration to cleanup idle connections // // Minimum time an object can be idle in the pool before being eligible // for eviction by the idle object evictor. // The default value is 30 minutes (1000 * 60 * 30). config.setMinEvictableIdleTimeMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); // Number of milliseconds to sleep between runs of idle object evictor thread. // Not using DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS since it is -1 // meaning it will not run the evictor thread and instead we're using // the default min value for evictable idle connections (Default 30 minutes) config.setTimeBetweenEvictionRunsMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); if (LOG.isDebugEnabled()) { LOG.debug("Config settings for idle object eviction: " + "time interval between eviction thread runs (" + config.getTimeBetweenEvictionRunsMillis() + " millis): minimum timeout for idle objects (" + config.getMinEvictableIdleTimeMillis() + " millis)"); } // Validate objects by the idle object evictor. If invalid, gets dropped // from the pool. config.setTestWhileIdle(true); // Validate object before borrowing from pool. If invalid, gets dropped // from the pool and an attempt to borrow another one will occur. config.setTestOnBorrow(true); return config; }
From source file:com.reversemind.hypergate.client.ClientPool.java
private static GenericObjectPoolConfig createConfig(int poolSize) { GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig(); genericObjectPoolConfig.setJmxEnabled(true); genericObjectPoolConfig.setJmxNameBase("HyperGatePool"); genericObjectPoolConfig.setJmxNamePrefix("HyperGatePoolPrefix"); genericObjectPoolConfig.setBlockWhenExhausted(false); genericObjectPoolConfig.setMinIdle(0); genericObjectPoolConfig.setTestOnBorrow(true); genericObjectPoolConfig.setMaxWaitMillis(500); START_POOL_SIZE = poolSize;// www. j a va 2s. c om genericObjectPoolConfig.setMaxTotal(START_POOL_SIZE); genericObjectPoolConfig.setMaxIdle(START_POOL_SIZE); return genericObjectPoolConfig; }
From source file:com.github.chrishantha.microbenchmark.objectpool.CommonsPool2GenericObjectPoolBenchmark.java
@Override public void setupObjectPool() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(poolSize); objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() { @Override/*from w w w . j a va 2s . c o m*/ public TestObject create() throws Exception { return new TestObject(true); } @Override public PooledObject<TestObject> wrap(TestObject testObject) { return new DefaultPooledObject<>(testObject); } }, config); }
From source file:com.newlandframework.rpc.serialize.hessian.HessianSerializePool.java
public HessianSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) { hessianPool = new GenericObjectPool<HessianSerialize>(new HessianSerializeFactory()); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxTotal); config.setMinIdle(minIdle);//w ww. j a va 2 s. c o m config.setMaxWaitMillis(maxWaitMillis); config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); hessianPool.setConfig(config); }
From source file:com.newlandframework.rpc.serialize.protostuff.ProtostuffSerializePool.java
public ProtostuffSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) { ProtostuffPool = new GenericObjectPool<ProtostuffSerialize>(new ProtostuffSerializeFactory()); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxTotal); config.setMinIdle(minIdle);//from w w w .j a v a2 s.c om config.setMaxWaitMillis(maxWaitMillis); config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); ProtostuffPool.setConfig(config); }
From source file:com.mycompany.amfclient.ConnectionPool.java
private ConnectionPool() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(200); this.connectionPool = new GenericObjectPool(ConnectionPooledFactory.inst(), config); }