本文整理汇总了Java中org.apache.commons.pool.impl.GenericObjectPool.setMaxIdle方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.setMaxIdle方法的具体用法?Java GenericObjectPool.setMaxIdle怎么用?Java GenericObjectPool.setMaxIdle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.setMaxIdle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureGenericObjectPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException {
SyslogPoolConfigIF poolConfig = null;
try {
poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig();
} catch (ClassCastException cce) {
throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF");
}
genericObjectPool.setMaxActive(poolConfig.getMaxActive());
genericObjectPool.setMaxIdle(poolConfig.getMaxIdle());
genericObjectPool.setMaxWait(poolConfig.getMaxWait());
genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
genericObjectPool.setMinIdle(poolConfig.getMinIdle());
genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow());
genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn());
genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle());
genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction());
}
示例2: getConnection
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public synchronized Connection getConnection(String nodeId) throws Exception {
GenericObjectPool<Connection> pool = poolMap.get(nodeId);
if (pool == null) {
PoolableObjectFactory<Connection> factory =
new SocketPoolFactory(nodeId, bufferSize, timeout);
pool = new GenericObjectPool<Connection>(factory);
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxIdle);
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
poolMap.put(nodeId, pool);
}
Connection con = pool.borrowObject();
con.setSoTimeout(timeout);
return con;
}
示例3: configureGenericObjectPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException {
SyslogPoolConfigIF poolConfig = null;
try {
poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig();
} catch (ClassCastException cce) {
throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF");
}
genericObjectPool.setMaxActive(poolConfig.getMaxActive());
genericObjectPool.setMaxIdle(poolConfig.getMaxIdle());
genericObjectPool.setMaxWait(poolConfig.getMaxWait());
genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
genericObjectPool.setMinIdle(poolConfig.getMinIdle());
genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow());
genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn());
genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle());
genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction());
}
示例4: createObjectPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* 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 org.apache.commons.pool.impl.GenericObjectPool
* @see #setMaxSize
*/
protected ObjectPool createObjectPool() {
GenericObjectPool gop = new GenericObjectPool(this);
gop.setMaxActive(getMaxSize());
gop.setMaxIdle(getMaxIdle());
gop.setMinIdle(getMinIdle());
gop.setMaxWait(getMaxWait());
gop.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
gop.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
gop.setWhenExhaustedAction(getWhenExhaustedAction());
return gop;
}
示例5: initializeDataSource
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* @param config
* @throws SQLException
*/
private void initializeDataSource(Config config) {
String user = config.getString(CONFIG_KEY_DB_USER);
String password = config.getString(CONFIG_KEY_DB_PASSWORD);
Properties params = new Properties();
if (isNotEmpty(user) && isNotEmpty(password)) {
params.put("user", user);
params.put("password", password);
}
// ドライバのロード
String driver = config.getString(CONFIG_KEY_DB_DRIVER);
boolean loadSuccess = DbUtils.loadDriver(driver);
if (!loadSuccess) {
String message = "failed to load driver.";
throw new RuntimeException(message);
}
// コネクションをプールするDataSource を作成する
@SuppressWarnings("rawtypes")
GenericObjectPool pool = new GenericObjectPool();
// コネクションプールの設定を行う
int maxActive = config.getInt(CONFIG_KEY_DB_MAX_ACTIVE_CONN, 100);
long maxWait = Long.parseLong(config.getString(CONFIG_KEY_DB_WAIT, "-1"));
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxActive);
pool.setMaxWait(maxWait);
driverUrl = config.getString(CONFIG_KEY_DB_URL);
ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, params);
new PoolableConnectionFactory(connFactory, pool, null,
null, // validationQuery
false, // defaultReadOnly
false); // defaultAutoCommit
dataSource = new PoolingDataSource(pool);
}
示例6: DxTransformer
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public DxTransformer() {
super();
transformerPool = new GenericObjectPool(new PooledDxTransformerFactory());
transformerPool.setMinIdle(MIN_IDLE_TRANSFORMERS);
transformerPool.setMaxIdle(MAX_IDLE_TRANSFORMERS);
transformerPool.setMaxActive(MAX_ACTIVE_TRANSFORMERS);
registerSourceType(DataTypeFactory.create(org.w3c.dom.Node.class));
registerSourceType(DataTypeFactory.create(InputSource.class));
registerSourceType(DataTypeFactory.create(NullPayload.class));
contextProperties = new HashMap<String, Object>();
}
示例7: configurePool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* Configures the database connection pool and sets the pool configuration.
*
* @param connectionPool
* The ObjectPool
* @param connectURI
* The url specifying the database to which it
* connects using JDBC
* @param pUserId
* The user id attribute
* @param pPassword
* The password attribute
*
* @throws java.lang.Exception
* Throws an SQL exception that provides
* information on a database access error
* or other errors
*
* @todo Make the pool access dynamic (use the dynamic class loader?)
* so that the application will compile/run without the Apache
* commons library.
*/
private void configurePool(GenericObjectPool connectionPool,
String connectURI, String pUserId, String pPassword) throws
Exception {
String lowerCaseConnectURI;
String validationQuery;
lowerCaseConnectURI = connectURI.toLowerCase();
validationQuery = null;
if (lowerCaseConnectURI.startsWith("jdbc:sybase")) {
validationQuery = "select getdate()";
} else if (lowerCaseConnectURI.startsWith("jdbc:mysql")) {
validationQuery = "select 1";
} else if (lowerCaseConnectURI.startsWith("jdbc:oracle")) {
validationQuery = "select sysdate from dual";
} else if (lowerCaseConnectURI.startsWith("jdbc:mssql")) {
validationQuery = "select 1";
}
// Pool settings - someday a dialog and persistence should be
// added to put these under user control
connectionPool.setMaxActive(1);
connectionPool.setWhenExhaustedAction(GenericObjectPool.
WHEN_EXHAUSTED_BLOCK);
connectionPool.setMaxWait(CONN_POOL_MAX_WAIT_MS);
connectionPool.setMaxIdle(CONN_POOL_MAX_IDLE_CONNECTIONS);
connectionPool
.setTimeBetweenEvictionRunsMillis(CONN_POOL_TIME_BETWEEN_EVICT_RUNS_MS);
connectionPool.setNumTestsPerEvictionRun(CONN_POOL_NUM_TESTS_PER_EVICT_RUN);
connectionPool.setMinEvictableIdleTimeMillis(CONN_POOL_EVICT_IDLE_TIME_MS);
final DriverManagerConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(connectURI, pUserId, pPassword);
final PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool, null,
null, false, true);
if (validationQuery != null) {
connectionPool.setTestOnBorrow(true);
connectionPool.setTestWhileIdle(true);
poolableConnectionFactory.setValidationQuery(validationQuery);
}
}
示例8: registerPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private synchronized void registerPool(
String username, String password)
throws javax.naming.NamingException, SQLException {
ConnectionPoolDataSource cpds = testCPDS(username, password);
Integer userMax = getPerUserMaxActive(username);
int maxActive = (userMax == null) ?
getDefaultMaxActive() : userMax.intValue();
userMax = getPerUserMaxIdle(username);
int maxIdle = (userMax == null) ?
getDefaultMaxIdle() : userMax.intValue();
userMax = getPerUserMaxWait(username);
int maxWait = (userMax == null) ?
getDefaultMaxWait() : userMax.intValue();
// Create an object pool to contain our PooledConnections
GenericObjectPool pool = new GenericObjectPool(null);
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxIdle);
pool.setMaxWait(maxWait);
pool.setWhenExhaustedAction(whenExhaustedAction(maxActive, maxWait));
pool.setTestOnBorrow(getTestOnBorrow());
pool.setTestOnReturn(getTestOnReturn());
pool.setTimeBetweenEvictionRunsMillis(
getTimeBetweenEvictionRunsMillis());
pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
pool.setTestWhileIdle(getTestWhileIdle());
// Set up the factory we will use (passing the pool associates
// the factory with the pool, so we do not have to do so
// explicitly)
CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, pool, getValidationQuery(),
isRollbackAfterValidation(), username, password);
Object old = managers.put(getPoolKey(username,password), factory);
if (old != null) {
throw new IllegalStateException("Pool already contains an entry for this user/password: "+username);
}
}
示例9: run
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private void run(int nrIterations, int nrThreads, int maxActive, int maxIdle) {
this.nrIterations = nrIterations;
init();
SleepingObjectFactory factory = new SleepingObjectFactory();
if (logLevel >= 4) { factory.setDebug(true); }
pool = new GenericObjectPool(factory);
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxIdle);
pool.setTestOnBorrow(true);
Thread[] threads = new Thread[nrThreads];
for (int i = 0; i < threads.length; i++) {
threads[i]= new Thread(new MyThread(), Integer.toString(i));
Thread.yield();
}
if (logLevel >= 1) { System.out.println("created"); }
Thread.yield();
for (int i = 0; i < threads.length; i++) {
threads[i].start();
Thread.yield();
}
if (logLevel >= 1) { System.out.println("started"); }
Thread.yield();
start = true;
if (logLevel >= 1) { System.out.println("go"); }
Thread.yield();
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (logLevel >= 1) { System.out.println("finish"); }
System.out.println("-----------------------------------------");
System.out.println("nrIterations: " + nrIterations);
System.out.println("nrThreads: " + nrThreads);
System.out.println("maxActive: " + maxActive);
System.out.println("maxIdle: " + maxIdle);
System.out.println("nrSamples: " + nrSamples);
System.out.println("totalBorrowTime: " + totalBorrowTime);
System.out.println("totalReturnTime: " + totalReturnTime);
System.out.println("avg BorrowTime: " + totalBorrowTime/nrSamples);
System.out.println("avg ReturnTime: " + totalReturnTime/nrSamples);
}
示例10: openConnectionPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public static void openConnectionPool(String pool_name, String driver_class, String uri, String user, String pass, int max_active, int max_idle)
throws SQLException
{
Properties props = new Properties();
props.put("autoReconnect","true");
props.put("user",user);
props.put("password",pass);
props.put("socketTimeout", "15");
loadDriver(driver_class);
loadDriver("org.apache.commons.dbcp.PoolingDriver");
GenericObjectPool connectionPool = new GenericObjectPool(null);
connectionPool.setMaxActive(max_active);
connectionPool.setMaxIdle(max_idle);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, props);
new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
driver.registerPool(pool_name,connectionPool);
}