commons-pool2-中的一些配置

        /**
                    * 连接失效检测相关
                    */
                   // 空闲时进行连接测试,会启动异步evict线程进行失效检测
                   setTestWhileIdle(true);
                   // 连接的空闲的最长时间,需要testWhileIdle为true,默认5分钟
                   setMinEvictableIdleTimeMillis(1000 * 60 * 5);
                   // 失效检测时间,需要testWhileIdle为true,默认5分钟
                   setTimeBetweenEvictionRunsMillis(1000 * 60 * 5);
                   // 每次检查连接的数量,需要testWhileIdle为true
                   setNumTestsPerEvictionRun(100);
                   // 获取连接时检测连接的有效性
                   setTestOnBorrow(true);
                   // 返还连接时检测连接的有效性
                   setTestOnReturn(false);
 
                   /**
                    * 连接池中连接数量相关
                    */
                   // 每个key对应的池最大连接数
                   setMaxTotalPerKey(20);
                   // 总连接数
                   setMaxTotal(40);
                   // 每个key对应的连接池最小空闲连接数
                   setMinIdlePerKey(5);
                   // 每个key对应的连接池最大空闲连接数
                   setMaxIdlePerKey(20);
 
                   /**
                    * 连接池无可用连接时相关
                    */
                   // 设置为true时,池中无可用连接,borrow时进行阻塞;为false时,当池中无可用连接,抛出NoSuchElementException异常
                   setBlockWhenExhausted(true);
                   // 多个任务需要borrow连接时,阻塞时是否采用公平策略,为true时采用,按照先申请先获得的策略进行borrow操作
                   setFairness(true);
                   // 最大等待时间,当需要borrow一个连接时,最大的等待时间,如果超出时间,抛出NoSuchElementException异常,-1为不限制时间
                   setMaxWaitMillis(-1);
posted @ 2015-11-22 12:57  yanzhenxing  阅读(2726)  评论(0编辑  收藏  举报