Java Code Examples for org.apache.commons.pool2.impl.GenericObjectPoolConfig#setMaxWaitMillis()
The following examples show how to use
org.apache.commons.pool2.impl.GenericObjectPoolConfig#setMaxWaitMillis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisConfig.java From jeesupport with MIT License | 6 votes |
@Bean public LettucePoolingClientConfiguration lettucePoolConfig( ClientOptions _co, ClientResources _cr ){ GenericObjectPoolConfig gopc = new GenericObjectPoolConfig(); gopc.setMaxIdle( CommonConfig.getInteger( "spring.redis.pool.max-idle", DEFAULT_MAX_IDLE ) ); gopc.setMinIdle( CommonConfig.getInteger( "spring.redis.pool.min-idle", DEFAULT_MIN_IDLE ) ); gopc.setMaxTotal( CommonConfig.getInteger( "spring.redis.pool.max-active", DEFAULT_MAX_TOTAL ) ); gopc.setMaxWaitMillis( CommonConfig.getLong( "spring.redis.pool.max-wait", DEFAULT_MAX_WAIT_MILLIS ) ); gopc.setEvictorShutdownTimeoutMillis( CommonConfig.getLong( "spring.redis.pool.timeout", DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS ) ); return LettucePoolingClientConfiguration.builder() .poolConfig( gopc ) .clientOptions( _co ) .clientResources( _cr ) .build(); }
Example 2
Source File: BrpcPooledChannel.java From brpc-java with Apache License 2.0 | 6 votes |
public BrpcPooledChannel(ServiceInstance serviceInstance, CommunicationOptions communicationOptions) { super(serviceInstance, communicationOptions); this.readTimeOut = communicationOptions.getReadTimeoutMillis(); this.latencyWindowSize = communicationOptions.getLatencyWindowSizeOfFairLoadBalance(); this.latencyWindow = new ConcurrentLinkedQueue<Integer>(); GenericObjectPoolConfig conf = new GenericObjectPoolConfig(); // Maximum waiting time, when you need to borrow a connection, the maximum waiting time, // if the time is exceeded, throw an exception, -1 is no time limit conf.setMaxWaitMillis(communicationOptions.getConnectTimeoutMillis()); conf.setMaxTotal(communicationOptions.getMaxTotalConnections()); conf.setMaxIdle(communicationOptions.getMaxTotalConnections()); conf.setMinIdle(communicationOptions.getMinIdleConnections()); // Connect test when idle, start asynchronous evict thread for failure detection conf.setTestWhileIdle(true); // Maximum time for connection idle, testWhileIdle needs to be true conf.setTimeBetweenEvictionRunsMillis(communicationOptions.getTimeBetweenEvictionRunsMillis()); channelFuturePool = new GenericObjectPool<Channel>(new ChannelPooledObjectFactory( this, serviceInstance.getIp(), serviceInstance.getPort()), conf); try { channelFuturePool.preparePool(); } catch (Exception ex) { log.warn("init min idle object pool failed"); } }
Example 3
Source File: RedisSinkBolt.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void prepare(Map conf, TopologyContext context, OutputCollector collector) { this.collector = collector; GenericObjectPoolConfig pconf = new GenericObjectPoolConfig(); pconf.setMaxWaitMillis(2000); pconf.setMaxTotal(1000); pconf.setTestOnBorrow(false); pconf.setTestOnReturn(false); pconf.setTestWhileIdle(true); pconf.setMinEvictableIdleTimeMillis(120000); pconf.setTimeBetweenEvictionRunsMillis(60000); pconf.setNumTestsPerEvictionRun(-1); pool = new JedisPool(pconf, redisHost, redisPort, timeout); }
Example 4
Source File: J2CacheRedisAutoConfiguration.java From Aooms with Apache License 2.0 | 6 votes |
private GenericObjectPoolConfig getGenericRedisPool(Properties props, String prefix) { GenericObjectPoolConfig cfg = new GenericObjectPoolConfig(); cfg.setMaxTotal(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxTotal"), "-1"))); cfg.setMaxIdle(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxIdle"), "100"))); cfg.setMaxWaitMillis(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxWaitMillis"), "100"))); cfg.setMinEvictableIdleTimeMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "minEvictableIdleTimeMillis"), "864000000"))); cfg.setMinIdle(Integer.valueOf((String) props.getOrDefault(key(prefix, "minIdle"), "10"))); cfg.setNumTestsPerEvictionRun( Integer.valueOf((String) props.getOrDefault(key(prefix, "numTestsPerEvictionRun"), "10"))); cfg.setLifo(Boolean.valueOf(props.getProperty(key(prefix, "lifo"), "false"))); cfg.setSoftMinEvictableIdleTimeMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "softMinEvictableIdleTimeMillis"), "10"))); cfg.setTestOnBorrow(Boolean.valueOf(props.getProperty(key(prefix, "testOnBorrow"), "true"))); cfg.setTestOnReturn(Boolean.valueOf(props.getProperty(key(prefix, "testOnReturn"), "false"))); cfg.setTestWhileIdle(Boolean.valueOf(props.getProperty(key(prefix, "testWhileIdle"), "true"))); cfg.setTimeBetweenEvictionRunsMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "timeBetweenEvictionRunsMillis"), "300000"))); cfg.setBlockWhenExhausted(Boolean.valueOf(props.getProperty(key(prefix, "blockWhenExhausted"), "false"))); return cfg; }
Example 5
Source File: J2CacheSpringRedisAutoConfiguration.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
private GenericObjectPoolConfig getGenericRedisPool(Properties props, String prefix) { GenericObjectPoolConfig cfg = new GenericObjectPoolConfig(); cfg.setMaxTotal(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxTotal"), "-1"))); cfg.setMaxIdle(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxIdle"), "100"))); cfg.setMaxWaitMillis(Integer.valueOf((String) props.getOrDefault(key(prefix, "maxWaitMillis"), "100"))); cfg.setMinEvictableIdleTimeMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "minEvictableIdleTimeMillis"), "864000000"))); cfg.setMinIdle(Integer.valueOf((String) props.getOrDefault(key(prefix, "minIdle"), "10"))); cfg.setNumTestsPerEvictionRun( Integer.valueOf((String) props.getOrDefault(key(prefix, "numTestsPerEvictionRun"), "10"))); cfg.setLifo(Boolean.valueOf(props.getProperty(key(prefix, "lifo"), "false"))); cfg.setSoftMinEvictableIdleTimeMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "softMinEvictableIdleTimeMillis"), "10"))); cfg.setTestOnBorrow(Boolean.valueOf(props.getProperty(key(prefix, "testOnBorrow"), "true"))); cfg.setTestOnReturn(Boolean.valueOf(props.getProperty(key(prefix, "testOnReturn"), "false"))); cfg.setTestWhileIdle(Boolean.valueOf(props.getProperty(key(prefix, "testWhileIdle"), "true"))); cfg.setTimeBetweenEvictionRunsMillis( Integer.valueOf((String) props.getOrDefault(key(prefix, "timeBetweenEvictionRunsMillis"), "300000"))); cfg.setBlockWhenExhausted(Boolean.valueOf(props.getProperty(key(prefix, "blockWhenExhausted"), "false"))); return cfg; }
Example 6
Source File: KryoSerialization.java From cuba with Apache License 2.0 | 6 votes |
protected void initPool() { // assume that application context is already initialized Configuration configuration = AppBeans.get(Configuration.NAME); config = configuration.getConfig(KryoSerializationConfig.class); int poolSize = config.getMaxPoolSize(); GenericObjectPoolConfig<Kryo> poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxIdle(poolSize); poolConfig.setMaxTotal(poolSize); poolConfig.setMaxWaitMillis(config.getMaxBorrowWaitMillis()); String jmxName = "kryo-" + AppContext.getProperty("cuba.webContextName"); poolConfig.setJmxNamePrefix(jmxName); PooledObjectFactory<Kryo> factory = new KryoObjectFactory(this); pool = new GenericObjectPool<>(factory, poolConfig); log.debug("Kryo context pool created"); }
Example 7
Source File: TransactionLegacy.java From cloudstack with Apache License 2.0 | 6 votes |
/** * Return a GenericObjectPoolConfig configuration usable on connection pool creation */ private static GenericObjectPoolConfig createPoolConfig(Integer maxActive, Integer maxIdle, Long maxWait, Long timeBtwnEvictionRuns, Long minEvictableIdleTime, Boolean testWhileIdle, Boolean testOnBorrow) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxActive); config.setMaxIdle(maxIdle); config.setMaxWaitMillis(maxWait); if (timeBtwnEvictionRuns != null) { config.setTimeBetweenEvictionRunsMillis(timeBtwnEvictionRuns); } if (minEvictableIdleTime != null) { config.setMinEvictableIdleTimeMillis(minEvictableIdleTime); } if (testWhileIdle != null) { config.setTestWhileIdle(testWhileIdle); } if (testOnBorrow != null) { config.setTestOnBorrow(testOnBorrow); } return config; }
Example 8
Source File: DefaultSessionPool.java From cyberduck with GNU General Public License v3.0 | 6 votes |
public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust, final X509KeyManager key, final VaultRegistry registry, final Cache<Path> cache, final TranscriptListener transcript, final Host bookmark) { this.connect = connect; this.registry = registry; this.cache = cache; this.bookmark = bookmark; this.transcript = transcript; final GenericObjectPoolConfig<Session> configuration = new GenericObjectPoolConfig<Session>(); configuration.setJmxEnabled(false); configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName()); configuration.setBlockWhenExhausted(true); configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL); this.pool = new GenericObjectPool<Session>(new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration); final AbandonedConfig abandon = new AbandonedConfig(); abandon.setUseUsageTracking(true); this.pool.setAbandonedConfig(abandon); }
Example 9
Source File: BaseTest.java From lite-pool with Apache License 2.0 | 5 votes |
public GenericObjectPool<TestObject> createCommonsPool2(int minimum, int maximum, long timeout) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maximum); config.setMinIdle(minimum); config.setMaxIdle(minimum); config.setFairness(false); config.setJmxEnabled(false); config.setBlockWhenExhausted(true); config.setTestOnBorrow(false); config.setMaxWaitMillis(timeout); config.setTestOnCreate(false); config.setTestOnReturn(false); config.setTestWhileIdle(false); return new GenericObjectPool<>( new CommonsPool2Factory(), config); }
Example 10
Source File: JedisManager.java From game-server with MIT License | 5 votes |
public JedisManager(JedisClusterConfig config) { HashSet<HostAndPort> jedisClusterNodes = new HashSet<>(); config.getNodes().forEach(node -> { if (node == null) { return; } try { if (node.getIp() != null && node.getIp().length() > 5) { jedisClusterNodes.add(new HostAndPort(node.getIp(), node.getPort())); } } catch (Exception e) { LOGGER.error(node.toString(), e); } }); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(config.getPoolMaxTotal()); poolConfig.setMaxIdle(config.getPoolMaxIdle()); poolConfig.setMaxWaitMillis(config.getMaxWaitMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis()); poolConfig.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis()); poolConfig.setSoftMinEvictableIdleTimeMillis(config.getSoftMinEvictableIdleTimeMillis()); poolConfig.setTestOnBorrow(config.isTestOnBorrow()); poolConfig.setTestWhileIdle(config.isTestWhileIdle()); poolConfig.setTestOnReturn(config.isTestOnReturn()); jedisCluster = new JedisCluster(jedisClusterNodes, config.getConnectionTimeout(), config.getSoTimeout(), config.getMaxRedirections(), poolConfig); }
Example 11
Source File: RedisAutoConfig.java From unimall with Apache License 2.0 | 5 votes |
@Bean public GenericObjectPoolConfig defaultPoolConfig() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxActive); config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); config.setMaxWaitMillis(maxWait); return config; }
Example 12
Source File: TestPoolingDriver.java From commons-dbcp with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() throws Exception { final DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null); final PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, null); pcf.setPoolStatements(true); pcf.setMaxOpenPreparedStatements(10); pcf.setValidationQuery("SELECT COUNT(*) FROM DUAL"); pcf.setDefaultReadOnly(Boolean.FALSE); pcf.setDefaultAutoCommit(Boolean.TRUE); final GenericObjectPoolConfig<PoolableConnection> poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxTotal(getMaxTotal()); poolConfig.setMaxWaitMillis(getMaxWaitMillis()); poolConfig.setMinIdle(10); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); poolConfig.setTestWhileIdle(true); poolConfig.setTimeBetweenEvictionRunsMillis(10000L); poolConfig.setNumTestsPerEvictionRun(5); poolConfig.setMinEvictableIdleTimeMillis(5000L); final GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<>(pcf, poolConfig); pcf.setPool(pool); assertNotNull(pcf); driver = new PoolingDriver(true); driver.registerPool("test",pool); }
Example 13
Source File: RedisConfiguration.java From ad with Apache License 2.0 | 5 votes |
@Bean public GenericObjectPoolConfig genericObjectPoolConfig() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxIdle(maxIdle); poolConfig.setMaxTotal(maxActive); poolConfig.setMinIdle(minIdle); poolConfig.setMaxWaitMillis(maxWait); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnCreate(true); poolConfig.setTestWhileIdle(true); return poolConfig; }
Example 14
Source File: RateLimiterPluginDataHandler.java From soul with Apache License 2.0 | 5 votes |
private GenericObjectPoolConfig<?> getPoolConfig(final RateLimiterConfig rateLimiterConfig) { GenericObjectPoolConfig<?> config = new GenericObjectPoolConfig<>(); config.setMaxTotal(rateLimiterConfig.getMaxActive()); config.setMaxIdle(rateLimiterConfig.getMaxIdle()); config.setMinIdle(rateLimiterConfig.getMinIdle()); if (rateLimiterConfig.getMaxWait() != null) { config.setMaxWaitMillis(rateLimiterConfig.getMaxWait().toMillis()); } return config; }
Example 15
Source File: JedisClusterTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test(expected = JedisConnectionException.class) public void testIfPoolConfigAppliesToClusterPools() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(0); config.setMaxWaitMillis(2000); Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); JedisCluster jc = new JedisCluster(jedisClusterNode, config); jc.set("52", "poolTestValue"); }
Example 16
Source File: RedisClusterBuilder.java From cachecloud with Apache License 2.0 | 5 votes |
/** * 构造函数package访问域,package外不能直接构造实例; * * @param appId */ RedisClusterBuilder(final long appId) { this.appId = appId; GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 5); poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 2); poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE); //JedisPool.borrowObject最大等待时间 poolConfig.setMaxWaitMillis(1000L); poolConfig.setJmxNamePrefix("jedis-pool"); poolConfig.setJmxEnabled(true); this.jedisPoolConfig = poolConfig; }
Example 17
Source File: HessianSerializePool.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
public HessianSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) { hessianPool = new GenericObjectPool<>(new HessianSerializeFactory()); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxTotal); config.setMinIdle(minIdle); config.setMaxWaitMillis(maxWaitMillis); config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); hessianPool.setConfig(config); }
Example 18
Source File: HessianSerializePool.java From Lottor with MIT License | 5 votes |
public HessianSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) { hessianPool = new GenericObjectPool<>(new HessianSerializeFactory()); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxTotal); config.setMinIdle(minIdle); config.setMaxWaitMillis(maxWaitMillis); config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); hessianPool.setConfig(config); }
Example 19
Source File: RedisClient.java From heisenberg with Apache License 2.0 | 4 votes |
private GenericObjectPoolConfig getConfig() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxWaitMillis(2000); return config; }
Example 20
Source File: RedisRegistry.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public RedisRegistry(URL url) { super(url); if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setTestOnBorrow(url.getParameter("test.on.borrow", true)); config.setTestOnReturn(url.getParameter("test.on.return", false)); config.setTestWhileIdle(url.getParameter("test.while.idle", false)); if (url.getParameter("max.idle", 0) > 0) config.setMaxIdle(url.getParameter("max.idle", 0)); if (url.getParameter("min.idle", 0) > 0) config.setMinIdle(url.getParameter("min.idle", 0)); if (url.getParameter("max.active", 0) > 0) config.setMaxTotal(url.getParameter("max.active", 0)); if (url.getParameter("max.total", 0) > 0) config.setMaxTotal(url.getParameter("max.total", 0)); if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0) config.setMaxWaitMillis(url.getParameter("max.wait", url.getParameter("timeout", 0))); if (url.getParameter("num.tests.per.eviction.run", 0) > 0) config.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0)); if (url.getParameter("time.between.eviction.runs.millis", 0) > 0) config.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0)); if (url.getParameter("min.evictable.idle.time.millis", 0) > 0) config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0)); String cluster = url.getParameter("cluster", "failover"); if (!"failover".equals(cluster) && !"replicate".equals(cluster)) { throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate."); } replicate = "replicate".equals(cluster); List<String> addresses = new ArrayList<String>(); addresses.add(url.getAddress()); String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]); if (backups != null && backups.length > 0) { addresses.addAll(Arrays.asList(backups)); } for (String address : addresses) { int i = address.indexOf(':'); String host; int port; if (i > 0) { host = address.substring(0, i); port = Integer.parseInt(address.substring(i + 1)); } else { host = address; port = DEFAULT_REDIS_PORT; } this.jedisPools.put(address, new JedisPool(config, host, port, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), StringUtils.isEmpty(url.getPassword()) ? null : url.getPassword(), url.getParameter("db.index", 0))); } this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD); String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); if (!group.startsWith(Constants.PATH_SEPARATOR)) { group = Constants.PATH_SEPARATOR + group; } if (!group.endsWith(Constants.PATH_SEPARATOR)) { group = group + Constants.PATH_SEPARATOR; } this.root = group; this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT); this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { deferExpired(); // Extend the expiration time } catch (Throwable t) { // Defensive fault tolerance logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t); } } }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS); }