org.apache.commons.pool2.impl.GenericObjectPoolConfig Java Examples

The following examples show how to use org.apache.commons.pool2.impl.GenericObjectPoolConfig. 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: GenerateEhCacheDefaultConfig.java    From dubbo-plus with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IllegalAccessException {
    CacheManager manager = CacheManager.create();
    Configuration configuration = manager.getConfiguration();
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    Object object= poolConfig;
    Field[] fields = object.getClass().getDeclaredFields();
    String prefix="cache.ehcache.";
    for(Field field:fields){
       field.setAccessible(true);
        Method method = getSetMethod(object.getClass(),field);
        if(method!=null&& CacheConfig.checkIsBasicType(field.getType())){
            System.out.println("#默认值"+field.get(object));
            System.out.println(prefix+field.getName());
        }
    }
}
 
Example #2
Source File: ApiLdapClientApiOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Override
protected void useBundleClasses() throws Exception
{
    new LdapNetworkConnection().close();
    new SaslGssApiRequest();
    new Krb5LoginConfiguration();
    new AddFuture( new LdapNetworkConnection(), 2 );
    new LdapConnectionTemplate( new LdapConnectionPool( new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() ) ) );
    FilterBuilder.and( FilterBuilder.not( FilterBuilder.contains( "cn", "a", "b" ) ) ).toString();

    // Test for DIRAPI-239
    PooledObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() );
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
    ldapConnectionPool.getLdapApiService();
    ldapConnectionPool.getTestOnBorrow();
    ldapConnectionPool.close();
}
 
Example #3
Source File: JedisClusterConnectionHandler.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPoolConfig poolConfig) {
  for (HostAndPort hostAndPort : startNodes) {
    Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort());
    try {
      cache.discoverClusterNodesAndSlots(jedis);
      break;
    } catch (JedisConnectionException e) {
      // try next nodes
    } finally {
      if (jedis != null) {
        jedis.close();
      }
    }
  }

  for (HostAndPort node : startNodes) {
    cache.setNodeIfNotExist(node);
  }
}
 
Example #4
Source File: ObjectPoolFactory.java    From Thunder with Apache License 2.0 6 votes vote down vote up
public static GenericObjectPoolConfig createFSTObjectPoolConfig() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    try {
        config.setMaxTotal(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MAX_TOTAL_ATTRIBUTE_NAME));
        config.setMaxIdle(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MAX_IDLE_ATTRIBUTE_NAME));
        config.setMinIdle(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MIN_IDLE_ATTRIBUTE_NAME));
        config.setMaxWaitMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_MAX_WAIT_MILLIS_ATTRIBUTE_NAME));
        config.setTimeBetweenEvictionRunsMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_TIME_BETWEEN_EVICTION_RUN_MILLIS_ATTRIBUTE_NAME));
        config.setMinEvictableIdleTimeMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS_ATTRIBUTE_NAME));
        config.setSoftMinEvictableIdleTimeMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_ATTRIBUTE_NAME));
        config.setBlockWhenExhausted(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_BLOCK_WHEN_EXHAUSTED_ATTRIBUTE_NAME));
        config.setLifo(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_LIFO_ATTRIBUTE_NAME));
        config.setFairness(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_FAIRNESS_ATTRIBUTE_NAME));
        config.setTestOnBorrow(false);
        config.setTestOnReturn(false);
        config.setTestOnCreate(false);
        config.setTestWhileIdle(false);
        config.setNumTestsPerEvictionRun(-1);
    } catch (Exception e) {
        throw new IllegalArgumentException("Properties maybe isn't initialized");
    }

    return config;
}
 
Example #5
Source File: BaseTestProxiedObjectPool.java    From commons-pool with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    log = new StringWriter();

    final PrintWriter pw = new PrintWriter(log);
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setLogAbandoned(true);
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setUseUsageTracking(true);
    abandonedConfig.setRemoveAbandonedTimeout(ABANDONED_TIMEOUT_SECS);
    abandonedConfig.setLogWriter(pw);

    final GenericObjectPoolConfig<TestObject> config = new GenericObjectPoolConfig<>();
    config.setMaxTotal(3);

    final PooledObjectFactory<TestObject> factory = new TestObjectFactory();

    @SuppressWarnings("resource")
    final ObjectPool<TestObject> innerPool =
            new GenericObjectPool<>(factory, config, abandonedConfig);

    pool = new ProxiedObjectPool<>(innerPool, getproxySource());
}
 
Example #6
Source File: PjedisPool.java    From pepper-metrics with Apache License 2.0 6 votes vote down vote up
public PjedisPool(final String host) {
  URI uri = URI.create(host);
  if (JedisURIHelper.isValid(uri)) {
    String h = uri.getHost();
    int port = uri.getPort();
    String password = JedisURIHelper.getPassword(uri);
    int database = JedisURIHelper.getDBIndex(uri);
    boolean ssl = uri.getScheme().equals("rediss");
    this.internalPool = new GenericObjectPool<Jedis>(new PjedisFactory(h, port,
        Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null,
          ssl, null, null, null), new GenericObjectPoolConfig());
  } else {
    this.internalPool = new GenericObjectPool<Jedis>(new PjedisFactory(host,
        Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
        Protocol.DEFAULT_DATABASE, null, false, null, null, null), new GenericObjectPoolConfig());
  }
}
 
Example #7
Source File: AbstractTestMode.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
public AbstractTestMode(HostPort master, List<HostPort> slaves, int producerThreadNum, int producerIntervalMicro, int msgSize, long maxKeys) {
    this.master = master;
    this.slaves = slaves;
    this.producerThreadNum = producerThreadNum;
    this.producerIntervalMicro = producerIntervalMicro;
    this.maxKeys = maxKeys;

    producerThreadPool = Executors.newScheduledThreadPool(producerThreadNum,
            XpipeThreadFactory.create("ProducerThreadPool"));
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(producerThreadNum * 3);
    dataPool = new GenericObjectPool<>(new BytesFactory(msgSize), config);
    consumerThreadPool = Executors.newFixedThreadPool(slaves.size() * 2 + 1, XpipeThreadFactory.create("ConsumerThreadPool"));
    qpsCheckThreadPool = Executors.newScheduledThreadPool(1, XpipeThreadFactory.create("QpsCheckThreadPool"));

    masterPool = getJedisPool(master.getHost(), master.getPort(), producerThreadNum * 2, producerThreadNum);
    beginSend = new DelayManager(qpsCheckThreadPool, "beginsend", master.toString(), TIME_TOO_LONG_TO_LOG_MILLI, false);
    slaves.forEach((slave) -> allDelays.put(slave, new DelayManager(qpsCheckThreadPool, "delay", String.format("%s.%d.%d.%d", slave.getHost(), slave.getPort(), producerThreadNum, producerIntervalMicro), TIME_TOO_LONG_TO_LOG_MILLI)));
    slaves.forEach((slave) -> slavePools.put(slave, getJedisPool(slave.getHost(), slave.getPort(), 2, 2)));

}
 
Example #8
Source File: KryoSerialization.java    From cuba with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: ShardedJedisPoolTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void checkConnectionWithDefaultPort() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  jedis.close();
  pool.destroy();
}
 
Example #10
Source File: RedisStandaloneBuilder.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数package访问域,package外直接构造实例;
 *
 * @param appId
 */
RedisStandaloneBuilder(final long appId) {
    this.appId = appId;
    poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 3);
    poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 2);
    poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE);
    poolConfig.setJmxEnabled(true);
    poolConfig.setJmxNamePrefix("jedis-pool");
}
 
Example #11
Source File: RedisAutoConfig.java    From unimall with Apache License 2.0 5 votes vote down vote up
/**** 缓存专用数据源 ****/
@Bean
public LettuceConnectionFactory defaultLettuceConnectionFactory(
        RedisStandaloneConfiguration defaultRedisConfig,GenericObjectPoolConfig defaultPoolConfig) {
    LettuceClientConfiguration clientConfig =
            LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(5000))
                    .poolConfig(defaultPoolConfig).build();
    return new LettuceConnectionFactory(defaultRedisConfig, clientConfig);
}
 
Example #12
Source File: ShardedJedisPoolTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void returnResourceShouldResetState() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("pipelined", String.valueOf(0));
  jedis.set("pipelined2", String.valueOf(0));

  ShardedJedisPipeline pipeline = jedis.pipelined();

  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");

  jedis.resetState();

  pipeline = jedis.pipelined();
  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");
  List<Object> results = pipeline.syncAndReturnAll();

  assertEquals(2, results.size());
  jedis.close();
  pool.destroy();
}
 
Example #13
Source File: Pool.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {

        if (this.internalPool != null) {
            try {
                closeInternalPool();
            } catch (Exception e) {
            }
        }

        this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
    }
 
Example #14
Source File: TracingJedisPool.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingJedisPool(final GenericObjectPoolConfig poolConfig, final URI uri,
    final SSLSocketFactory sslSocketFactory,
    final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier,
    TracingConfiguration tracingConfiguration) {
  super(poolConfig, uri, sslSocketFactory, sslParameters, hostnameVerifier);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #15
Source File: CommonsPool2TargetSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(getMaxSize());
	config.setMaxIdle(getMaxIdle());
	config.setMinIdle(getMinIdle());
	config.setMaxWaitMillis(getMaxWait());
	config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
	config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
	config.setBlockWhenExhausted(isBlockWhenExhausted());
	return new GenericObjectPool(this, config);
}
 
Example #16
Source File: JedisManager.java    From game-server with MIT License 5 votes vote down vote up
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 #17
Source File: SvnObjectPools.java    From proctor with Apache License 2.0 5 votes vote down vote up
private static <T> ObjectPool<T> createObjectPool(final PooledObjectFactory<T> factory) {
    final GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
    objectPoolConfig.setMinEvictableIdleTimeMillis(TimeUnit.HOURS.toMillis(1)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setJmxEnabled(false);
    objectPoolConfig.setBlockWhenExhausted(false);
    objectPoolConfig.setMaxTotal(-1); // uncapped number of objects in the pool
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setRemoveAbandonedTimeout((int) TimeUnit.MINUTES.toSeconds(30));
    return new GenericObjectPool<T>(factory, objectPoolConfig, abandonedConfig);
}
 
Example #18
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingJedisCluster(HostAndPort node, int connectionTimeout, int soTimeout,
    int maxAttempts,
    String password, GenericObjectPoolConfig poolConfig,
    TracingConfiguration tracingConfiguration) {
  super(node, connectionTimeout, soTimeout, maxAttempts, password, poolConfig);
  this.helper = new TracingHelper(tracingConfiguration);
}
 
Example #19
Source File: ProtostuffSerializePool.java    From Raincat with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ProtostuffSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) {
    protostuffPool = new GenericObjectPool<>(new ProtostuffSerializeFactory());
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(maxTotal);
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    protostuffPool.setConfig(config);
}
 
Example #20
Source File: JedisPoolTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");

  Jedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
  } finally {
    jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } finally {
    jedis2.close();
  }

  pool.destroy();
  assertTrue(pool.isClosed());
}
 
Example #21
Source File: LettuceConnFactoryProvider.java    From sofa-dashboard-client with Apache License 2.0 5 votes vote down vote up
private GenericObjectPoolConfig getPoolConfig(Pool properties) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(properties.getMaxActive());
    config.setMaxIdle(properties.getMaxIdle());
    config.setMinIdle(properties.getMinIdle());
    if (properties.getMaxWait() != null) {
        config.setMaxWaitMillis(properties.getMaxWait().toMillis());
    }
    return config;
}
 
Example #22
Source File: TracingJedisPool.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingJedisPool(final GenericObjectPoolConfig poolConfig, final String host,
    final int port,
    final int timeout, final String password, final boolean ssl,
    final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
    final HostnameVerifier hostnameVerifier, TracingConfiguration tracingConfiguration) {
  super(poolConfig, host, port, timeout, password, ssl, sslSocketFactory, sslParameters,
      hostnameVerifier);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #23
Source File: TracingJedisSentinelPool.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingJedisSentinelPool(TracingConfiguration tracingConfiguration, String masterName,
    Set<String> sentinels,
    final GenericObjectPoolConfig poolConfig) {
  super(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null,
      Protocol.DEFAULT_DATABASE);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #24
Source File: DataSourceFactoryTest.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Test
public void testPoolConfigZeroValues() {
   
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "0");
    
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    
    // MaxTotal and MaxIdle are set to -1 if the value is 0
    assertEquals(config.getMaxTotal(), -1);
    assertEquals(config.getMaxIdle(), -1);
    assertEquals(config.getMinIdle(), 0);
    assertEquals(config.getMaxWaitMillis(), 0);
    assertEquals(config.getMinEvictableIdleTimeMillis(), 0);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), 0);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
    
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
 
Example #25
Source File: Pool.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {

    if (this.internalPool != null) {
      try {
        closeInternalPool();
      } catch (Exception e) {
      }
    }

    this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
  }
 
Example #26
Source File: DataLoaderFactory.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
private DataLoaderFactory() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1024);
    config.setMaxIdle(50);
    config.setMinIdle(8);
    // 当Pool中没有对象时不等待,而是直接new个新的
    config.setBlockWhenExhausted(false);

    AbandonedConfig abandonConfig = new AbandonedConfig();
    abandonConfig.setRemoveAbandonedTimeout(300);
    abandonConfig.setRemoveAbandonedOnBorrow(true);
    abandonConfig.setRemoveAbandonedOnMaintenance(true);
    factory = new GenericObjectPool<DataLoader>(this, config, abandonConfig);
}
 
Example #27
Source File: CommonsPool2TargetSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(getMaxSize());
	config.setMaxIdle(getMaxIdle());
	config.setMinIdle(getMinIdle());
	config.setMaxWaitMillis(getMaxWait());
	config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
	config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
	config.setBlockWhenExhausted(isBlockWhenExhausted());
	return new GenericObjectPool(this, config);
}
 
Example #28
Source File: PjedisPool.java    From pepper-metrics with Apache License 2.0 5 votes vote down vote up
public PjedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port,
                 int timeout, final String password, final int database, final String clientName,
                 final boolean ssl, final SSLSocketFactory sslSocketFactory,
                 final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
  this(poolConfig, host, port, timeout, timeout, password, database, clientName, ssl,
          sslSocketFactory, sslParameters, hostnameVerifier);
}
 
Example #29
Source File: DBCPPool.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initDefault() {
	setProperty("defaultAutoCommit",TRUE);
	setProperty("cacheState",TRUE);
	setProperty("lifo",String.valueOf(BaseObjectPoolConfig.DEFAULT_LIFO));
	setProperty("maxTotal",String.valueOf(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL));
	setProperty("maxIdle",String.valueOf(GenericObjectPoolConfig.DEFAULT_MAX_IDLE));
	setProperty("minIdle",String.valueOf(GenericObjectPoolConfig.DEFAULT_MIN_IDLE));
	setProperty("initialSize","3");
	setProperty("maxWaitMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS));
	setProperty("poolPreparedStatements",FALSE);
	setProperty("maxOpenPreparedStatements",String.valueOf(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL));
	setProperty("timeBetweenEvictionRunsMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
	setProperty("numTestsPerEvictionRun",String.valueOf(BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
	setProperty("minEvictableIdleTimeMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
	setProperty("softMinEvictableIdleTimeMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
	setProperty("evictionPolicyClassName",String.valueOf(BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME));
	setProperty("testWhileIdle",FALSE);
	setProperty("validationQuery","");
	setProperty("validationQueryTimeoutSeconds","-1");
	setProperty("accessToUnderlyingConnectionAllowed",FALSE);
	setProperty("maxConnLifetimeMILLIS","-1");
	setProperty("logExpiredConnections",TRUE);
	setProperty("jmxName","org.magic.api:type=Pool,name="+getName());
	setProperty("autoCommitOnReturn",TRUE);
	setProperty("rollbackOnReturn",TRUE);
	setProperty("defaultAutoCommit",TRUE);
	setProperty("defaultReadOnly",FALSE);
	setProperty("defaultQueryTimeoutSeconds","");
	setProperty("cacheState",TRUE);
	setProperty("testOnCreate",FALSE);
	setProperty("testOnBorrow",TRUE);
	setProperty("testOnReturn",FALSE);
	setProperty("fastFailValidation",FALSE);
}
 
Example #30
Source File: SerConnInstance.java    From migration-tool with Apache License 2.0 5 votes vote down vote up
private void init_pool_config() {
	config = new GenericObjectPoolConfig();
	config.setLifo(Config.getBoolean("lifo"));
	config.setMaxTotal(Config.getInt("maxTotal"));
	config.setMaxIdle(Config.getInt("maxIdle"));
	config.setMaxWaitMillis(Config.getLong("maxWait"));
	config.setMinEvictableIdleTimeMillis(Config.getLong("minEvictableIdleTimeMillis"));
	config.setMinIdle(Config.getInt("minIdle"));
	config.setNumTestsPerEvictionRun(Config.getInt("numTestsPerEvictionRun"));
	config.setTestOnBorrow(Config.getBoolean("testOnBorrow"));
	config.setTestOnReturn(Config.getBoolean("testOnReturn"));
	config.setTestWhileIdle(Config.getBoolean("testWhileIdle"));
	config.setTimeBetweenEvictionRunsMillis(Config.getLong("timeBetweenEvictionRunsMillis"));
}