List of usage examples for org.apache.commons.pool2.impl GenericObjectPool setMinIdle
public void setMinIdle(int minIdle)
From source file:io.seldon.dbcp.DbcpFactory.java
private void createDbcp(DbcpConfig conf) { if (!dataSources.containsKey(conf.name)) { try {//from w w w.j a v a 2 s . c om Class.forName(conf.driverClassName); DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory(conf.jdbc, conf.user, conf.password); PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, null); pcf.setValidationQuery(conf.validationQuery); //, pool, null, conf.validationQuery, false, true,abandondedConfig); logger.info("Creating pool " + conf.toString()); // create a generic pool GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pcf); pool.setMaxTotal(conf.maxTotal); pool.setMaxIdle(conf.maxIdle); pool.setMinIdle(conf.minIdle); pool.setMaxWaitMillis(conf.maxWait); pool.setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); pool.setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); pool.setTestWhileIdle(conf.testWhileIdle); pool.setTestOnBorrow(conf.testOnBorrow); AbandonedConfig abandonedConfig = new AbandonedConfig(); abandonedConfig.setRemoveAbandonedOnMaintenance(conf.removeAbanadoned); abandonedConfig.setRemoveAbandonedTimeout(conf.removeAbandonedTimeout); abandonedConfig.setLogAbandoned(conf.logAbandonded); pool.setAbandonedConfig(abandonedConfig); pcf.setPool(pool); DataSource ds = new PoolingDataSource(pool); dataSources.put(conf.name, ds); } catch (ClassNotFoundException e) { logger.error( "Failed to create datasource for " + conf.name + " with class " + conf.driverClassName); } } else { logger.error("Pool " + conf.name + " already exists. Can't change existing datasource at present."); } }
From source file:net.identio.server.service.authentication.ldap.LdapAuthenticationProvider.java
private void initPool(List<LdapAuthMethod> ldapAuthMethods) { for (LdapAuthMethod ldapAuthMethod : ldapAuthMethods) { LOG.debug("* Auth Method: {}", ldapAuthMethod.getName()); LdapConnectionFactory factory = new LdapConnectionFactory(ldapAuthMethod); GenericObjectPool<InitialLdapContext> pool = new GenericObjectPool<>(factory); LdapAuthenticationProviderConfiguration.LdapPoolConfig poolConfig = ldapAuthMethod.getPoolConfig(); pool.setMinIdle(poolConfig.getMinIdleConnections()); pool.setMaxIdle(poolConfig.getMaxIdleConnections()); pool.setBlockWhenExhausted(true); pool.setTestWhileIdle(poolConfig.isTestWhileIdle()); pool.setTestOnBorrow(poolConfig.isTestOnBorrow()); pool.setTimeBetweenEvictionRunsMillis(1000 * poolConfig.getTimeBetweenEvictionRuns()); pool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun()); pool.setMinEvictableIdleTimeMillis(1000 * poolConfig.getMinEvictableIdleTime()); pools.put(ldapAuthMethod.getName(), pool); }/*from www. ja v a 2 s . c o m*/ }
From source file:com.adaptris.core.services.splitter.ServiceWorkerPool.java
public GenericObjectPool<Worker> createCommonsObjectPool() throws CoreException { GenericObjectPool<Worker> pool = new GenericObjectPool<>(new WorkerFactory()); // Make the pool the same size as the thread pool pool.setMaxTotal(maxThreads);/*from w ww . j ava2 s . c om*/ pool.setMinIdle(maxThreads); pool.setMaxIdle(maxThreads); pool.setMaxWaitMillis(-1L); pool.setBlockWhenExhausted(true); pool.setSoftMinEvictableIdleTimeMillis(EVICT_RUN); pool.setTimeBetweenEvictionRunsMillis(EVICT_RUN + ThreadLocalRandom.current().nextLong(EVICT_RUN)); return pool; }
From source file:com.adaptris.core.services.splitter.ServiceWorkerPool.java
/** * /*from ww w . java2s.c o m*/ * @deprecated since 3.8.3 switch to commons-pool2 and {@link createCommonsObjectPool()} instead. */ @Deprecated @Removal(version = "3.9.0", message = "use commons-pool2 + createCommonsObjectPool()") public org.apache.commons.pool.impl.GenericObjectPool<Worker> createObjectPool() throws CoreException { logDeprecationWarning(); org.apache.commons.pool.impl.GenericObjectPool<Worker> pool = new org.apache.commons.pool.impl.GenericObjectPool( new LegacyCommonsPoolWorkerFactory()); pool.setMaxActive(maxThreads); pool.setMinIdle(maxThreads); pool.setMaxIdle(maxThreads); pool.setMaxWait(-1L); pool.setWhenExhaustedAction(org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMinEvictableIdleTimeMillis(EVICT_RUN); pool.setTimeBetweenEvictionRunsMillis(EVICT_RUN + ThreadLocalRandom.current().nextLong(EVICT_RUN)); return pool; }
From source file:com.adaptris.core.PoolingWorkflow.java
private GenericObjectPool<Worker> createObjectPool() { GenericObjectPool<Worker> pool = new GenericObjectPool<>(new WorkerFactory()); long lifetime = threadLifetimeMs(); pool.setMaxTotal(poolSize());/* w w w .jav a 2 s.c om*/ pool.setMinIdle(minIdle()); pool.setMaxIdle(maxIdle()); pool.setMaxWaitMillis(-1L); pool.setBlockWhenExhausted(true); pool.setSoftMinEvictableIdleTimeMillis(lifetime); pool.setTimeBetweenEvictionRunsMillis(lifetime + ThreadLocalRandom.current().nextLong(lifetime)); return pool; }
From source file:com.zaxxer.hikari.benchmark.BenchBase.java
private void setupDBCP2() { org.apache.commons.pool2.impl.GenericObjectPool<org.apache.commons.dbcp2.PoolableConnection> connectionPool; DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(jdbcURL, "sa", ""); // Wrap the connections and statements with pooled variants org.apache.commons.dbcp2.PoolableConnectionFactory poolableCF = null; poolableCF = new org.apache.commons.dbcp2.PoolableConnectionFactory(connectionFactory, null); poolableCF.setValidationQuery("VALUES 1"); poolableCF.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); poolableCF.setDefaultAutoCommit(false); poolableCF.setRollbackOnReturn(true); // Create the actual pool of connections, and apply any properties connectionPool = new org.apache.commons.pool2.impl.GenericObjectPool(poolableCF); connectionPool.setTestOnBorrow(true); connectionPool.setMaxIdle(maxPoolSize); connectionPool.setMinIdle(MIN_POOL_SIZE); connectionPool.setMaxTotal(maxPoolSize); connectionPool.setMaxWaitMillis(8000); connectionPool.setMinEvictableIdleTimeMillis((int) TimeUnit.MINUTES.toMillis(30)); poolableCF.setPool(connectionPool);/* www . j a va 2 s. c om*/ DS = new org.apache.commons.dbcp2.PoolingDataSource(connectionPool); }