public static ZKPool getZkPool(String zkAddr) throws PlatformException { if (pools.get(zkAddr) == null) { synchronized (LOCK) { if (pools.get(zkAddr) == null) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(total); config.setTestOnBorrow(false); config.setMinIdle(10); int timeOut = 2000; if (StringUtils.isBlank(zkAddr)) { throw new PlatformException( ZkErrorCodeConstants.NO_PARSE_ZK_INFO, "zkAddr can not be null,and its format is ip:port"); } if (!StringUtils.isBlank(zkTimeout)) { timeOut = Integer.parseInt(zkTimeout); } ZKPool zkPool = new ZKPool(config, zkAddr, timeOut); pools.put(zkAddr, zkPool); } } } return pools.get(zkAddr); }
{ super.setMaxIdle(6); super.setMaxTotal(40); super.setMinIdle(1); super.setTimeBetweenEvictionRunsMillis(1000L * 60L * 10L); super.setNumTestsPerEvictionRun(10); super.setMinEvictableIdleTimeMillis(1000L * 60L * 5L); }
static { // int timeOut = PGHelper.toInteger(Config.getParam("mysql", "timeout")); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMinIdle(1); config.setMaxIdle(4); config.setTestOnBorrow(true); config.setTestOnCreate(true); config.setTestOnReturn(true); // pool = new GenericObjectPool<Connection>(SQLConnectionFactory.getInstance(), config); dataSource = SQLConnectionFactory.getInstance().createDataSoure(); }
public synchronized void init() { if (status != 0) { throw new RuntimeException("client has inited"); } else { status = 1; } // 配置基本属性 GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setTestOnBorrow(true); poolConfig.setJmxEnabled(true); poolConfig.setMaxTotal(maxTotal); poolConfig.setMaxIdle(maxIdle); poolConfig.setMinIdle(minIdle); poolConfig.setTimeBetweenEvictionRunsMillis(1000 * 60 * 5); poolConfig.setNumTestsPerEvictionRun(10); AbandonedConfig abandonedConfig = new AbandonedConfig(); ConnectionPoolFactory factory = new ConnectionPoolFactory(servers, soTimeout, ioMode); pool = new GenericObjectPool<Connection>(factory, poolConfig, abandonedConfig); }