org.apache.commons.pool2.impl.BaseObjectPoolConfig Java Examples
The following examples show how to use
org.apache.commons.pool2.impl.BaseObjectPoolConfig.
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: DataSourceFactoryTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testPoolConfigDefaultValues() { GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig(); assertNotNull(config); assertEquals(config.getMaxTotal(), GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); assertEquals(config.getMaxIdle(), GenericObjectPoolConfig.DEFAULT_MAX_IDLE); assertEquals(config.getMinIdle(), GenericObjectPoolConfig.DEFAULT_MIN_IDLE); assertEquals(config.getMaxWaitMillis(), GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS); assertEquals(config.getMinEvictableIdleTimeMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); assertEquals(config.getTimeBetweenEvictionRunsMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); assertTrue(config.getTestWhileIdle()); assertTrue(config.getTestOnBorrow()); }
Example #2
Source File: DataSourceFactoryTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testPoolConfigInvalidValues() { System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "a"); System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "b"); System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "c"); System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "d"); System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "e"); System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "f"); GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig(); assertNotNull(config); assertEquals(config.getMaxTotal(), GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); assertEquals(config.getMaxIdle(), GenericObjectPoolConfig.DEFAULT_MAX_IDLE); assertEquals(config.getMinIdle(), GenericObjectPoolConfig.DEFAULT_MIN_IDLE); assertEquals(config.getMaxWaitMillis(), GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS); assertEquals(config.getMinEvictableIdleTimeMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); assertEquals(config.getTimeBetweenEvictionRunsMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 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 #3
Source File: DBCPPool.java From MtgDesktopCompanion with GNU General Public License v3.0 | 5 votes |
@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 #4
Source File: DataSourceFactory.java From athenz with Apache License 2.0 | 4 votes |
public static GenericObjectPoolConfig setupPoolConfig() { // setup config vars for the object pool // ie. min and max idle instances, and max total instances of arbitrary objects GenericObjectPoolConfig config = new GenericObjectPoolConfig(); // The maximum number of active connections that can be allocated from // this pool at the same time, or negative for no limit. Default: 8 config.setMaxTotal(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL)); if (config.getMaxTotal() == 0) { config.setMaxTotal(-1); // -1 means no limit } // The maximum number of connections that can remain idle in the pool, // without extra ones being released, or negative for no limit. Default 8 config.setMaxIdle(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE)); if (config.getMaxIdle() == 0) { config.setMaxIdle(-1); // -1 means no limit } // The minimum number of connections that can remain idle in the pool, // without extra ones being created, or zero to create none. Default 0 config.setMinIdle(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE)); // The maximum number of milliseconds that the pool will wait (when // there are no available connections) for a connection to be returned // before throwing an exception, or -1 to wait indefinitely. Default -1 config.setMaxWaitMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_WAIT, GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); // setup the configuration to cleanup idle connections // // Minimum time an object can be idle in the pool before being eligible // for eviction by the idle object evictor. // The default value is 30 minutes (1000 * 60 * 30). config.setMinEvictableIdleTimeMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); // Number of milliseconds to sleep between runs of idle object evictor thread. // Not using DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS since it is -1 // meaning it will not run the evictor thread and instead we're using // the default min value for evictable idle connections (Default 30 minutes) config.setTimeBetweenEvictionRunsMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); if (LOG.isDebugEnabled()) { LOG.debug("Config settings for idle object eviction: " + "time interval between eviction thread runs (" + config.getTimeBetweenEvictionRunsMillis() + " millis): minimum timeout for idle objects (" + config.getMinEvictableIdleTimeMillis() + " millis)"); } // Validate objects by the idle object evictor. If invalid, gets dropped // from the pool. config.setTestWhileIdle(true); // Validate object before borrowing from pool and returning to the pool. // If invalid, gets dropped from the pool and an attempt to borrow // another one will occur. config.setTestOnBorrow(true); config.setTestOnReturn(true); return config; }
Example #5
Source File: ObjectPoolIssue326.java From commons-pool with Apache License 2.0 | 4 votes |
private void run() throws Exception { final GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig(); poolConfig.setMaxTotal(10); poolConfig.setMaxTotalPerKey(5); poolConfig.setMinIdlePerKey(-1); poolConfig.setMaxIdlePerKey(-1); poolConfig.setLifo(true); poolConfig.setFairness(true); poolConfig.setMaxWaitMillis(30 * 1000); poolConfig.setMinEvictableIdleTimeMillis(-1); poolConfig.setSoftMinEvictableIdleTimeMillis(-1); poolConfig.setNumTestsPerEvictionRun(1); poolConfig.setTestOnCreate(false); poolConfig.setTestOnBorrow(false); poolConfig.setTestOnReturn(false); poolConfig.setTestWhileIdle(false); poolConfig.setTimeBetweenEvictionRunsMillis(5 * 1000); poolConfig.setEvictionPolicyClassName(BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME); poolConfig.setBlockWhenExhausted(false); poolConfig.setJmxEnabled(false); poolConfig.setJmxNameBase(null); poolConfig.setJmxNamePrefix(null); final GenericKeyedObjectPool<Integer, Object> pool = new GenericKeyedObjectPool<>(new ObjectFactory(), poolConfig); // number of threads to reproduce is finicky. this count seems to be best for my // 4 core box. // too many doesn't reproduce it ever, too few doesn't either. final ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); final long startTime = System.currentTimeMillis(); long testIter = 0; try { while (true) { testIter++; if (testIter % 1000 == 0) { System.out.println(testIter); } final List<Task> tasks = createTasks(pool); final List<Future<Object>> futures = service.invokeAll(tasks); for (final Future<Object> future : futures) { future.get(); } } } finally { System.out.println("Time: " + (System.currentTimeMillis() - startTime) / 1000.0); service.shutdown(); } }