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);
相关文章
相关标签/搜索