本文整理匯總了Java中org.apache.commons.pool.impl.GenericObjectPool.setMaxActive方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericObjectPool.setMaxActive方法的具體用法?Java GenericObjectPool.setMaxActive怎麽用?Java GenericObjectPool.setMaxActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.pool.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.setMaxActive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
示例4: 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());
}
示例5: 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;
}
示例6: 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);
}
示例7: setUp
import org.apache.commons.pool.impl.GenericObjectPool; //導入方法依賴的package包/類
/**
*
* @return @throws Exception
*/
public DataSource setUp() throws Exception {
/**
* Load JDBC Driver class.
*/
Class.forName(ConnectionPool.DRIVER).newInstance();
/**
* Creates an instance of GenericObjectPool that holds our pool of
* connections object.
*/
connectionPool = new GenericObjectPool();
// set the max number of connections
connectionPool.setMaxActive(connections);
// if the pool is exhausted (i.e., the maximum number of active objects has been reached), the borrowObject() method should simply create a new object anyway
connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
/**
* Creates a connection factory object which will be used by the pool to
* create the connection object. We pass the JDBC url info, username
* and password.
*/
ConnectionFactory cf = new DriverManagerConnectionFactory(
ConnectionPool.URL,
ConnectionPool.USERNAME,
ConnectionPool.PASSWORD);
/**
* Creates a PoolableConnectionFactory that will wrap the connection
* object created by the ConnectionFactory to add object pooling
* functionality.
*/
PoolableConnectionFactory pcf
= new PoolableConnectionFactory(cf, connectionPool,
null, null, false, true);
return new PoolingDataSource(connectionPool);
}
示例8: setUp
import org.apache.commons.pool.impl.GenericObjectPool; //導入方法依賴的package包/類
public DataSource setUp() throws Exception {
Class.forName(DBPool.DRIVER).newInstance(); //Load driver
//Create pool
connectionPool = new GenericObjectPool();
connectionPool.setMaxActive(DBPool.POOL_SIZE);
//Create factor
ConnectionFactory cf = new DriverManagerConnectionFactory(DBPool.URL,DBPool.USER,DBPool.PASSWORD);
//Create PoolableConnectionFactory
PoolableConnectionFactory pcf =
new PoolableConnectionFactory(cf, connectionPool,
null, null, false, true);
return new PoolingDataSource(connectionPool);
}
示例9: 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);
}
示例10: 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>();
}
示例11: addNewPool
import org.apache.commons.pool.impl.GenericObjectPool; //導入方法依賴的package包/類
public void addNewPool(String dbDriver, String dbServer, String dbLogin, String dbPassword,
int minConns, int maxConns, double maxConnTime, String dbSessionConfig, String _rdbms,
String name) throws Exception {
if (this.defaultPoolName == null || this.defaultPoolName.equals("")) {
this.defaultPoolName = name;
this.bbdd = dbServer;
this.rdbms = _rdbms;
}
if (externalConnectionPool != null) {
// No need to create and add a new pool
return;
}
log4j.debug("Loading underlying JDBC driver.");
try {
Class.forName(dbDriver);
} catch (ClassNotFoundException e) {
throw new Exception(e);
}
log4j.debug("Done.");
GenericObjectPool connectionPool = new GenericObjectPool(null);
connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
connectionPool.setMaxActive(maxConns);
connectionPool.setTestOnBorrow(false);
connectionPool.setTestOnReturn(false);
connectionPool.setTestWhileIdle(false);
KeyedObjectPoolFactory keyedObject = new StackKeyedObjectPoolFactory();
ConnectionFactory connectionFactory = new OpenbravoDriverManagerConnectionFactory(dbServer,
dbLogin, dbPassword, dbSessionConfig, _rdbms);
@SuppressWarnings("unused")
// required by dbcp
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, connectionPool, keyedObject, null, false, true);
Class.forName("org.apache.commons.dbcp.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
driver.registerPool(contextName + "_" + name, connectionPool);
}
示例12: setupDataSource
import org.apache.commons.pool.impl.GenericObjectPool; //導入方法依賴的package包/類
/**
*
* @param connectURI - JDBC Connection URI
* @param username - JDBC Connection username
* @param password - JDBC Connection password
* @param minIdle - Minimum number of idel connection in the connection pool
* @param maxActive - Connection Pool Maximum Capacity (Size)
* @param timeout - timeout
* @throws Exception
*/
public static DataSource setupDataSource(String connectURI,
String username,
String password,
int minIdle, int maxActive, int timeout
) throws Exception {
//
// First, we'll need a ObjectPool that serves as the
// actual pool of connections.
//
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
GenericObjectPool connectionPool = new GenericObjectPool(null);
connectionPool.setMinIdle( minIdle );
connectionPool.setMaxActive( maxActive );
ConnectionManager._pool = connectionPool;
// we keep it for two reasons
// #1 We need it for statistics/debugging
// #2 PoolingDataSource does not have getPool()
// method, for some obscure, weird reason.
//
// Next, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string from configuration
//
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(connectURI,username, password);
//
// Now we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
//
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(
connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource =
new PoolingDataSource(connectionPool);
return dataSource;
}
示例13: setupDataSource
import org.apache.commons.pool.impl.GenericObjectPool; //導入方法依賴的package包/類
/**
*
* @param connectURI
* - JDBC Connection URI
* @param username
* - JDBC Connection username
* @param password
* - JDBC Connection password
* @param minIdle
* - Minimum number of idle connection in the connection pool
* @param maxActive
* - Connection Pool Maximum Capacity (Size)
* @throws Exception
*/
public DataSource setupDataSource(String connectURI,
String username, String password, int minIdle, int maxActive)
throws Exception {
//
// First, we'll need a ObjectPool that serves as the
// actual pool of connections.
//
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
GenericObjectPool connectionPool = new GenericObjectPool(null);
connectionPool.setMinIdle(minIdle);
connectionPool.setMaxActive(maxActive);
_pool = connectionPool;
// we keep it for two reasons
// #1 We need it for statistics/debugging
// #2 PoolingDataSource does not have getPool()
// method, for some obscure, weird reason.
//
// Next, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string from configuration
//
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
connectURI, username, password);
//
// Now we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
//
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, connectionPool, null, null, false, true);
poolableConnectionFactory.setValidationQuery(getDbType().getValidationQuery());
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
return dataSource;
}
示例14: 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);
}
}
示例15: 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);
}
}