Example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxIdle

List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxIdle

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxIdle.

Prototype

public void setMaxIdle(int maxIdle) 

Source Link

Document

Set the value for the maxIdle configuration attribute for pools created with this configuration instance.

Usage

From source file:com.gxl.test.shark.resource.redisSetData.java

public @BeforeClass static void init() {
    GenericObjectPoolConfig cfg = new GenericObjectPoolConfig();
    cfg.setMaxIdle(10);
    cfg.setMinIdle(1);/*w w  w  .ja  va 2 s.c  om*/
    cfg.setMaxIdle(5);
    cfg.setMaxWaitMillis(5000);
    cfg.setTestOnBorrow(true);
    cfg.setTestOnReturn(true);
    Set<HostAndPort> hostAndPorts = new HashSet<HostAndPort>();
    HostAndPort hostAndPort = new HostAndPort("120.24.75.22", 7000);
    hostAndPorts.add(hostAndPort);
    jedis = new JedisCluster(hostAndPorts, cfg);
}

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);
    config.setMaxTotal(maxPoolSize);//w  w w.j  ava2  s .c o m
    config.setMaxWaitMillis(keepAliveTime);

    return config;
}

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);/*  w w  w  .j a  va2  s.c  o  m*/
    objectPoolConfig.setMaxIdle(100);
    httpClientManager.setObjectPoolConfig(objectPoolConfig);
    httpClientManager.setBorrowMaxWaitMillis(10000);
    return httpClientManager;
}

From source file:net.greghaines.jesque.utils.PoolUtils.java

/**
 * @return a GenericObjectPoolConfig configured with: maxActive=-1,
 * maxIdle=10, minIdle=1, testOnBorrow=true,
 * blockWhenExhausted=false/*from  w  w  w. j a  va2  s  .  c  o  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 {//from w  w  w  .ja  v a2  s  . com
        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.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;/* w  w w .  j  a v a2  s. c  o m*/
    genericObjectPoolConfig.setMaxTotal(START_POOL_SIZE);
    genericObjectPoolConfig.setMaxIdle(START_POOL_SIZE);
    return genericObjectPoolConfig;
}

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(/*www  .  ja  va  2  s.c o m*/
            retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL));
    if (config.getMaxTotal() == 0) {
        config.setMaxTotal(-1); // -1 means no limit
    }

    //  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.zxy.commons.redis.RedisPoolFactory.java

private RedisPoolFactory() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(RedisPropUtils.getMaxIdle());
    poolConfig.setMinIdle(RedisPropUtils.getMinIdle());
    poolConfig.setMaxTotal(RedisPropUtils.getMaxTotal());
    poolConfig.setMaxWaitMillis(RedisPropUtils.getMaxWaitMillis());
    poolConfig.setTimeBetweenEvictionRunsMillis(RedisPropUtils.getTimeBetweenEvictionRunsMillis());
    poolConfig.setMinEvictableIdleTimeMillis(RedisPropUtils.getMinEvictableIdleTimeMillis());
    poolConfig.setTestWhileIdle(RedisPropUtils.getTestWhileIdle());
    poolConfig.setTestOnBorrow(RedisPropUtils.getTestOnBorrow());

    Set<String> hosts = RedisPropUtils.getServers();
    if (hosts.size() > 1) {
        throw new IllegalArgumentException("ip port??!");
    }/* w w  w.  j  ava  2 s . co  m*/
    HostAndPort hostAndPort = RedisPropUtils.getServer();
    int timeout = RedisPropUtils.getTimeout();
    this.jedisPool = new JedisPool(poolConfig, hostAndPort.getHost(), hostAndPort.getPort(), timeout);
}

From source file:io.lettuce.core.support.GenericConnectionPoolBenchmark.java

@Setup
public void setup() {

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMinIdle(0);// w w  w  .  j  a  va  2 s  . co m
    config.setMaxIdle(20);
    config.setMaxTotal(20);

    pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> new EmptyStatefulRedisConnection(EmptyRedisChannelWriter.INSTANCE), config);
}

From source file:com.zxy.commons.redis.RedisClusterFactory.java

private RedisClusterFactory() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(RedisPropUtils.getMaxIdle());
    poolConfig.setMinIdle(RedisPropUtils.getMinIdle());
    poolConfig.setMaxTotal(RedisPropUtils.getMaxTotal());
    poolConfig.setMaxWaitMillis(RedisPropUtils.getMaxWaitMillis());
    poolConfig.setTimeBetweenEvictionRunsMillis(RedisPropUtils.getTimeBetweenEvictionRunsMillis());
    poolConfig.setMinEvictableIdleTimeMillis(RedisPropUtils.getMinEvictableIdleTimeMillis());
    poolConfig.setTestWhileIdle(RedisPropUtils.getTestWhileIdle());
    poolConfig.setTestOnBorrow(RedisPropUtils.getTestOnBorrow());

    int timeout = RedisPropUtils.getTimeout();
    Set<HostAndPort> haps = parseHostAndPort();
    int maxRedirections = RedisPropUtils.getMaxRedirections();
    if (maxRedirections <= 0) {
        maxRedirections = 5;// w  w w  . j a  v a 2 s .c om
    }
    jedisCluster = new JedisCluster(haps, timeout, maxRedirections, poolConfig);
}