本文整理汇总了Java中org.apache.commons.pool.impl.GenericObjectPool.setMaxWait方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.setMaxWait方法的具体用法?Java GenericObjectPool.setMaxWait怎么用?Java GenericObjectPool.setMaxWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.setMaxWait方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setUp
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public void setUp() throws Exception {
super.setUp();
pool = new GenericObjectPool();
pool.setMaxActive(getMaxActive());
pool.setMaxWait(getMaxWait());
Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "password");
PoolableConnectionFactory factory =
new PoolableConnectionFactory(
new DriverConnectionFactory(new TesterDriver(),
"jdbc:apache:commons:testdriver", props),
pool, null, "SELECT DUMMY FROM DUAL", true, true);
pool.setFactory(factory);
ds = new PoolingDataSource(pool);
ds.setAccessToUnderlyingConnectionAllowed(true);
}
示例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: setUp
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public void setUp() throws Exception {
super.setUp();
// create a GeronimoTransactionManager for testing
transactionManager = new TransactionManagerImpl();
// create a driver connection factory
Properties properties = new Properties();
properties.setProperty("user", "username");
properties.setProperty("password", "password");
ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);
// wrap it with a LocalXAConnectionFactory
XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(transactionManager, connectionFactory);
// create the pool
pool = new GenericObjectPool();
pool.setMaxActive(getMaxActive());
pool.setMaxWait(getMaxWait());
// create the pool object factory
PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, pool, null, "SELECT DUMMY FROM DUAL", true, true);
pool.setFactory(factory);
// finally create the datasource
ds = new ManagedDataSource(pool, xaConnectionFactory.getTransactionRegistry());
ds.setAccessToUnderlyingConnectionAllowed(true);
}
示例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);
}
}