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); }
@Test public void testGetResourceValidate() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setTestOnBorrow(true); pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.afterPropertiesSet(); RedisAsyncConnection<byte[], byte[]> client = pool.getResource(); assertNotNull(client); client.close(); }
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); }