objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns); objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun); objectPool.setTestOnReturn(testOnReturn); objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis); objectPool.setLifo(lifo);
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public void setConfig(GenericObjectPool.Config conf) { synchronized (this) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); } allocate(); }
/** * Sets the <code>testOnReturn</code> property. This property determines * whether or not the pool will validate objects before they are returned * to the pool. For a <code>true</code> value to have any effect, the * <code>validationQuery</code> property must be set to a non-null string. * * @param testOnReturn new value for testOnReturn property */ public synchronized void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; if (connectionPool != null) { connectionPool.setTestOnReturn(testOnReturn); } }
/** * Sets the <code>testOnReturn</code> property. This property determines * whether or not the pool will validate objects before they are returned * to the pool. For a <code>true</code> value to have any effect, the * <code>validationQuery</code> property must be set to a non-null string. * * @param testOnReturn new value for testOnReturn property */ public void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; if (sessionPool != null) { sessionPool.setTestOnReturn(testOnReturn); } }
/** * Sets the <code>testOnReturn</code> property. This property determines * whether or not the pool will validate objects before they are returned * to the pool. For a <code>true</code> value to have any effect, the * <code>validationQuery</code> property must be set to a non-null string. * * @param testOnReturn new value for testOnReturn property */ public synchronized void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; if (connectionPool != null) { connectionPool.setTestOnReturn(testOnReturn); } }
/** * Sets the <code>testOnReturn</code> property. This property determines * whether or not the pool will validate objects before they are returned * to the pool. For a <code>true</code> value to have any effect, the * <code>validationQuery</code> property must be set to a non-null string. * * @param testOnReturn new value for testOnReturn property */ public synchronized void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; if (connectionPool != null) { connectionPool.setTestOnReturn(testOnReturn); } }
/** * Sets the <code>testOnReturn</code> property. This property determines * whether or not the pool will validate objects before they are returned * to the pool. For a <code>true</code> value to have any effect, the * <code>validationQuery</code> property must be set to a non-null string. * * @param testOnReturn new value for testOnReturn property */ public synchronized void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; if (connectionPool != null) { connectionPool.setTestOnReturn(testOnReturn); } }
GenericObjectPool connectionPool = new GenericObjectPool(null); connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 30); connectionPool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30); connectionPool.setNumTestsPerEvictionRun(3); connectionPool.setTestOnBorrow(true); connectionPool.setTestWhileIdle(false); connectionPool.setTestOnReturn(false); props = new Properties(); props.put("user", username); props.put("password", password); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, props); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, "SELECT 1", false, true); PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
public static DataSource getPoolingDataSourceFromConf(Configuration conf) { final ConnectionFactory cf = new DriverManagerConnectionFactory( conf.get(LensConfConstants.SERVER_DB_JDBC_URL, LensConfConstants.DEFAULT_SERVER_DB_JDBC_URL), conf.get(LensConfConstants.SERVER_DB_JDBC_USER, LensConfConstants.DEFAULT_SERVER_DB_USER), conf.get(LensConfConstants.SERVER_DB_JDBC_PASS, LensConfConstants.DEFAULT_SERVER_DB_PASS)); final GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setTestOnBorrow(false); connectionPool.setTestOnReturn(false); connectionPool.setTestWhileIdle(true); new PoolableConnectionFactory(cf, connectionPool, null, conf.get(LensConfConstants.SERVER_DB_VALIDATION_QUERY, LensConfConstants.DEFAULT_SERVER_DB_VALIDATION_QUERY), false, false).setDefaultAutoCommit(true); return new PoolingDataSource(connectionPool); }
@Override public void afterPropertiesSet() throws Exception { // 对象池 objectPool = new GenericObjectPool<TTransport>(); // ((GenericObjectPool<TTransport>) objectPool).setMaxActive(maxActive); ((GenericObjectPool<TTransport>) objectPool).setMaxIdle(maxIdle); ((GenericObjectPool<TTransport>) objectPool).setMinIdle(minIdle); ((GenericObjectPool<TTransport>) objectPool).setMaxWait(maxWait); ((GenericObjectPool<TTransport>) objectPool).setTestOnBorrow(testOnBorrow); ((GenericObjectPool<TTransport>) objectPool).setTestOnReturn(testOnReturn); ((GenericObjectPool<TTransport>) objectPool).setTestWhileIdle(testWhileIdle); ((GenericObjectPool<TTransport>) objectPool).setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); // 设置factory ThriftPoolableObjectFactory thriftPoolableObjectFactory = new ThriftPoolableObjectFactory(serviceIP, servicePort, conTimeOut); ((GenericObjectPool<TTransport>) objectPool).setFactory(thriftPoolableObjectFactory); }
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public synchronized void setConfig(GenericObjectPool.Config conf) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); allocate(); }
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public synchronized void setConfig(GenericObjectPool.Config conf) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); allocate(); }
/** * Creates a connection pool for this datasource. This method only exists * so subclasses can replace the implementation class. */ protected void createConnectionPool() { // Create an object pool to contain our active connections GenericObjectPool gop; if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) { gop = new AbandonedObjectPool(null,abandonedConfig); } else { gop = new GenericObjectPool(); } gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; }
/** * Creates a connection pool for this datasource. This method only exists * so subclasses can replace the implementation class. */ protected void createConnectionPool() { // Create an object pool to contain our active connections GenericObjectPool gop; if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) { gop = new AbandonedObjectPool(null,abandonedConfig); } else { gop = new GenericObjectPool(); } gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; }
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public void setConfig(GenericObjectPool.Config conf) { synchronized (this) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); } allocate(); }
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public void setConfig(GenericObjectPool.Config conf) { synchronized (this) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); } allocate(); }
private synchronized GenericObjectPool createPool() { if (closed) { throw new RedisException("Data source is closed"); } if (connectionPool == null) { GenericObjectPool gop = new GenericObjectPool(); gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; createConnectionFactory(); try { for (int i = 0; i < initialSize; i++) { connectionPool.addObject(); } } catch (Exception e) { throw new RedisException("Error preloading the connection pool", e); } } return connectionPool; }
this.connectionPool.setMinIdle ( getInteger ( paramProperties, PREFIX + "minIdle", 1 ) ); this.connectionPool.setTestOnBorrow ( getBoolean ( paramProperties, PREFIX + "testOnBorrow", true ) ); this.connectionPool.setTestOnReturn ( getBoolean ( paramProperties, PREFIX + "testOnReturn", true ) );
protected void configureGenericObjectPool(GenericObjectPool<AbstractSyslogWriter> genericObjectPool) throws SyslogRuntimeException { SyslogPoolConfigIF poolConfig = null; try { poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig(); } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF"); } genericObjectPool.setMaxActive(poolConfig.getMaxActive()); genericObjectPool.setMaxIdle(poolConfig.getMaxIdle()); genericObjectPool.setMaxWait(poolConfig.getMaxWait()); genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis()); genericObjectPool.setMinIdle(poolConfig.getMinIdle()); genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun()); genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis()); genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow()); genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn()); genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle()); genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis()); genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction()); }
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException { SyslogPoolConfigIF poolConfig = null; try { poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig(); } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF"); } genericObjectPool.setMaxActive(poolConfig.getMaxActive()); genericObjectPool.setMaxIdle(poolConfig.getMaxIdle()); genericObjectPool.setMaxWait(poolConfig.getMaxWait()); genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis()); genericObjectPool.setMinIdle(poolConfig.getMinIdle()); genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun()); genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis()); genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow()); genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn()); genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle()); genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis()); genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction()); }