jedis连接池

  public static JedisPool getPool() {
        if (jedisPool == null) {
            JedisPoolConfig config = new JedisPoolConfig();

            config.setMaxTotal(2048);//最大连接数, 默认8个
            config.setMaxIdle(200);//最大空闲连接数, 默认8个
            config.setBlockWhenExhausted(true);//(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常
            config.setMaxWaitMillis(3*1000L);//超时毫秒数,小于零:阻塞不确定的时间,  默认-1
            config.setNumTestsPerEvictionRun(1024); // always test all idle objects
            config.setTimeBetweenEvictionRunsMillis(1 * 60000L); //-1不启动。默认1min一次
            config.setMinEvictableIdleTimeMillis(10 * 60000L); //可发呆的时间,10mins

            config.setTestOnReturn(false);
            config.setTestWhileIdle(true);//发呆过长移除的时候是否test一下先
            config.setTestOnBorrow(true);//在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
            jedisPool = new JedisPool(config, "10.0.0.18", 6379);
        }
        return jedisPool;
    }


    /**
     * Return jedis connection to the pool, call different return methods depends on the conectionBroken status.
     */
    protected static void closeResource(Jedis jedis) {
        jedis.close();
    }

你可能感兴趣的:(jedis)