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

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

Introduction

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

Prototype

public void setMaxWaitMillis(long maxWaitMillis) 

Source Link

Document

Set the value for the maxWait 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);//from w  w  w.  j a  va2s. c  o m
    cfg.setMinIdle(1);
    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);/* w  w w . j av a  2s.  co  m*/
    config.setMaxTotal(maxPoolSize);
    config.setMaxWaitMillis(keepAliveTime);

    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;/*w ww  .  j a v a  2s . c  o m*/
    genericObjectPoolConfig.setMaxTotal(START_POOL_SIZE);
    genericObjectPoolConfig.setMaxIdle(START_POOL_SIZE);
    return genericObjectPoolConfig;
}

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);//from   ww w.j a  v  a2 s  . com
    config.setMinIdle(minIdle);
    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);//  w  w  w.  j  a  v a  2 s  . co  m
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    ProtostuffPool.setConfig(config);
}

From source file:dictinsight.redis.JedisInstance.java

public JedisInstance() {
    boolean online = FileUtils.getBooleanConfig(RedisConst.filename, "online", false);
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    if (online) {
        List<String> seedList = HttpUtils.getSvnConfServer(RedisConst.seedList);
        for (String seed : seedList) {
            String[] s = seed.split(":");
            try {
                jedisClusterNodes.add(new HostAndPort(s[0], Integer.valueOf(s[1])));
                System.out.println("connect to rediscluster:" + s[0]);
            } catch (Exception e) {
                e.printStackTrace();//from w  w w  .  j  av  a 2 s  . co  m
            }
        }
    } else {
        String host = FileUtils.getStringConfig(RedisConst.filename, "redis-hosts", "nc042x");
        String ports = FileUtils.getStringConfig(RedisConst.filename, "redis-port",
                "7000:7001:7002:7003:7004:7005");
        String[] portArray = ports.split(":");
        for (String port : portArray) {
            jedisClusterNodes.add(new HostAndPort(host, Integer.valueOf(port)));
            System.out.println("connect to " + host);
        }
    }

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(200);
    poolConfig.setMaxIdle(20);
    poolConfig.setMinIdle(10);
    poolConfig.setMaxWaitMillis(5 * 1000);
    poolConfig.setTimeBetweenEvictionRunsMillis(5 * 60 * 1000);
    poolConfig.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy");
    poolConfig.setSoftMinEvictableIdleTimeMillis(2 * 60 * 1000);
    jedis = new JedisCluster(jedisClusterNodes, DEFAULT_TIMEOUT, 3, poolConfig);
}

From source file:com.pytsoft.cachelock.LockSmithTest_RedisCluster_Jedis.java

@Before
public void init() {
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    HostAndPort hostAndPort = new HostAndPort(this.cacheServerHost, this.redisServerPort);
    jedisClusterNodes.add(hostAndPort);//from w  w  w.jav  a2  s.  c om

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setBlockWhenExhausted(true);
    config.setMaxTotal(20);
    config.setMaxIdle(10);
    config.setMinIdle(5);
    config.setMaxWaitMillis(5000);

    this.cluster = new JedisCluster(jedisClusterNodes, 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??!");
    }//from   www  .ja  v a2  s . co  m
    HostAndPort hostAndPort = RedisPropUtils.getServer();
    int timeout = RedisPropUtils.getTimeout();
    this.jedisPool = new JedisPool(poolConfig, hostAndPort.getHost(), hostAndPort.getPort(), timeout);
}

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;/*from   www.j  av  a  2s . c  o m*/
    }
    jedisCluster = new JedisCluster(haps, timeout, maxRedirections, poolConfig);
}

From source file:com.lambdaworks.redis.RedisConnectionPool.java

/**
 * Create a new connection pool// w  ww.  j  a  v  a 2 s . c o  m
 * 
 * @param redisConnectionProvider the connection provider
 * @param maxActive max active connections
 * @param maxIdle max idle connections
 * @param maxWait max wait time (ms) for a connection
 */
public RedisConnectionPool(RedisConnectionProvider<T> redisConnectionProvider, int maxActive, int maxIdle,
        long maxWait) {
    this.redisConnectionProvider = redisConnectionProvider;

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(maxIdle);
    config.setMaxTotal(maxActive);
    config.setMaxWaitMillis(maxWait);
    config.setTestOnBorrow(true);

    objectPool = new GenericObjectPool<>(createFactory(redisConnectionProvider), config);
}