Java Code Examples for org.apache.commons.pool.impl.GenericObjectPool#setMaxActive()

The following examples show how to use org.apache.commons.pool.impl.GenericObjectPool#setMaxActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyedResourcePool.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds the given resource factory.
 * @param resourceFactory The {@link ResourceFactory} to add.
 * @exception Exception error populating the pool
 */
public void addResourceFactory(
        final ResourceFactory<T> resourceFactory) throws Exception {
    final PoolableObjectFactory<T> factory =
        new PoolableResourceFactory<T>(resourceFactory);
    final GenericObjectPool<T> pool = new GenericObjectPool<T>(factory);
    final int instances = resourceFactory.getInstances();
    pool.setMinIdle(instances);
    pool.setMaxActive(instances);
    pool.setMaxIdle(instances);
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
    final String type = resourceFactory.getType();
    pools.put(type, pool);
    LOGGER.info("loading " + instances + " instance(s) of type '" + type
            + "'");
    for (int i = 0; i < instances; i++) {
        pool.addObject();
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("...resources loaded.");
    }
}
 
Example 2
Source File: GenericSyslogPoolFactory.java    From syslog4j with GNU Lesser General Public License v2.1 6 votes vote down vote up
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());
}
 
Example 3
Source File: GenericSyslogPoolFactory.java    From syslog4j-graylog2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
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());
}
 
Example 4
Source File: CommonsPoolTargetSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see org.apache.commons.pool.impl.GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
	GenericObjectPool gop = new GenericObjectPool(this);
	gop.setMaxActive(getMaxSize());
	gop.setMaxIdle(getMaxIdle());
	gop.setMinIdle(getMinIdle());
	gop.setMaxWait(getMaxWait());
	gop.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
	gop.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
	gop.setWhenExhaustedAction(getWhenExhaustedAction());
	return gop;
}
 
Example 5
Source File: ConnectionPoolingIT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
private PoolingDataSource setUpPoolingDataSource() throws Exception
{
  Class.forName(BaseJDBCTest.DRIVER_CLASS);
  connectionPool = new GenericObjectPool();
  connectionPool.setMaxActive(20);
  return new PoolingDataSource(connectionPool);
}
 
Example 6
Source File: ElexisPoolingDataSource.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private ObjectPool<Connection> createConnectionPool(DBConnection dbConnection)
	throws InstantiationException, IllegalAccessException, ClassNotFoundException{
	String driverName = StringUtils.defaultString(dbConnection.rdbmsType.driverName);
	String username = StringUtils.defaultString(dbConnection.username);
	String password = StringUtils.defaultString(dbConnection.password);
	String jdbcString = StringUtils.defaultString(dbConnection.connectionString);
	
	Driver driver = (Driver) Class.forName(driverName).newInstance();
	
	Properties properties = new Properties();
	properties.put("user", username);
	properties.put("password", password);
	
	log.info("db connection pool [" + driver + ", " + jdbcString + ", " + username
		+ "] initialization");
	
	ConnectionFactory connectionFactory =
		new DriverConnectionFactory(driver, jdbcString, properties);
	
	GenericObjectPool<Connection> connectionPool = new GenericObjectPool<>(null);
	connectionPool.setMaxActive(32);
	connectionPool.setMinIdle(8);
	connectionPool.setMaxWait(10000);
	connectionPool.setTestOnBorrow(true);
	
	new PoolableConnectionFactory(connectionFactory, connectionPool, null, "SELECT 1;", false,
		true);
	return connectionPool;
	
}
 
Example 7
Source File: DB.java    From jelectrum with MIT License 3 votes vote down vote up
public static void openConnectionPool(String pool_name, String driver_class, String uri, String user, String pass, int max_active, int max_idle)
    throws SQLException
{

    Properties props = new Properties();
    props.put("autoReconnect","true");
    props.put("user",user);
    props.put("password",pass);
    props.put("socketTimeout", "15");

    loadDriver(driver_class);
    loadDriver("org.apache.commons.dbcp.PoolingDriver");


    GenericObjectPool connectionPool = new GenericObjectPool(null);

    connectionPool.setMaxActive(max_active);
    connectionPool.setMaxIdle(max_idle);

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, props);

    new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);

    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");

    driver.registerPool(pool_name,connectionPool);

}