本文整理匯總了Java中org.apache.commons.dbcp2.BasicDataSource.setRemoveAbandonedOnMaintenance方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDataSource.setRemoveAbandonedOnMaintenance方法的具體用法?Java BasicDataSource.setRemoveAbandonedOnMaintenance怎麽用?Java BasicDataSource.setRemoveAbandonedOnMaintenance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.dbcp2.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setRemoveAbandonedOnMaintenance方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invokeGetDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst02");
bds.setUsername("root");
bds.setPassword("123456");
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例2: invokeGetDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst01");
bds.setUsername("root");
bds.setPassword("123456");
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例3: getInitializedDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private BasicDataSource getInitializedDataSource(MySQLConfig mySqlConfig) {
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName(mySqlConfig.getDriverClass());
basicDataSource.setUrl(mySqlConfig.getUrl());
basicDataSource.setUsername(mySqlConfig.getUsername());
basicDataSource.setPassword(mySqlConfig.getPassword());
basicDataSource.setRemoveAbandonedTimeout(mySqlConfig.getRemoveAbandonedTimeoutInSeconds());
basicDataSource.setRemoveAbandonedOnBorrow(mySqlConfig.isAbleToRemoveAbandonedConnections());
basicDataSource.setRemoveAbandonedOnMaintenance(mySqlConfig.isAbleToRemoveAbandonedConnections());
// int maxValue = 100;
// basicDataSource.setMaxIdle(maxValue);
// basicDataSource.setMaxTotal(maxValue);
return basicDataSource;
}
示例4: initialize
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public static void initialize(String driverName, String driverUrl, String userName, String password) throws SQLException {
dataSource = new BasicDataSource();
dataSource.setDriverClassName(driverName);
dataSource.setUsername(userName);
dataSource.setPassword(password);
dataSource.setUrl(driverUrl);
dataSource.setDefaultReadOnly(false);
dataSource.setDefaultAutoCommit(false);
// enable detection and logging of connection leaks
dataSource.setRemoveAbandonedOnBorrow(true);
dataSource.setRemoveAbandonedOnMaintenance(true);
dataSource.setRemoveAbandonedTimeout(3600); // 1 hour
dataSource.setLogAbandoned(true);
dataSource.setMaxWaitMillis(60000);
dataSource.setMaxTotal(20);
INITDATE = new Date();
}
示例5: SQLDatabase
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
*
* Constructor for a database instance.
*
* @param jdbcInfo the driver you are using
* @param username login name
* @param password password
* @param database database name
* @param host host for the connection
* @param port port of the SQL server
*
*/
public SQLDatabase(SQLDatabaseType jdbcInfo, String username, String password, String database, String host,
int port) {
this.jdbcInfo = jdbcInfo;
this.username = username;
this.password = password;
this.host = host;
this.port = port;
this.database = database;
BasicDataSource ds = new BasicDataSource();
String urlPrefix = jdbcInfo.getURLPrefix(this.host, this.database, this.port)
+ "?autoReconnect=true&useSSL=false&serverTimezone=UTC";
ds.setUrl(urlPrefix);
ds.setUsername(username);
ds.setPassword(password);
ds.setDriverClassName(jdbcInfo.getDriverName());
ds.setPoolPreparedStatements(true);
ds.setTestOnBorrow(true);
ds.setRemoveAbandonedOnBorrow(true);
ds.setRemoveAbandonedOnMaintenance(true);
ds.setMaxOpenPreparedStatements(100);
ds.setMaxConnLifetimeMillis(1000 * 60 * 60);
dataSource = ds;
setValidationQuery();
}
示例6: getDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
* NOTE: This method must not use log4j for logging as this may cause locking issues
*/
@Override
public DataSource getDataSource() {
// PostgreSQL does not provide connection pool (as of version 42.1.3) so make one using Apache Commons DBCP
ds = new BasicDataSource();
// max number of active connections
Integer maxTotal = AtsSystemProperties.getPropertyAsNumber("dbcp.maxTotal");
if (maxTotal == null) {
maxTotal = 8;
} else {
log.info("Max number of active connections is "
+ maxTotal);
}
ds.setMaxTotal(maxTotal);
// wait time for new connection
Integer maxWaitMillis = AtsSystemProperties.getPropertyAsNumber("dbcp.maxWaitMillis");
if (maxWaitMillis == null) {
maxWaitMillis = 60 * 1000;
} else {
log.info("Connection creation wait is "
+ maxWaitMillis
+ " msec");
}
ds.setMaxWaitMillis(maxWaitMillis);
String logAbandoned = System.getProperty("dbcp.logAbandoned");
if (logAbandoned != null && ("true".equalsIgnoreCase(logAbandoned))
|| "1".equalsIgnoreCase(logAbandoned)) {
String removeAbandonedTimeoutString = System.getProperty("dbcp.removeAbandonedTimeout");
int removeAbandonedTimeout = (int) ds.getMaxWaitMillis() / (2 * 1000);
if (!StringUtils.isNullOrEmpty(removeAbandonedTimeoutString)) {
removeAbandonedTimeout = Integer.parseInt(removeAbandonedTimeoutString);
}
log.info(
"Will log and remove abandoned connections if not cleaned in "
+ removeAbandonedTimeout
+ " sec");
// log not closed connections
ds.setLogAbandoned(true); // issue stack trace of not closed connection
ds.setAbandonedUsageTracking(true);
ds.setLogExpiredConnections(true);
ds.setRemoveAbandonedTimeout(removeAbandonedTimeout);
ds.setRemoveAbandonedOnBorrow(true);
ds.setRemoveAbandonedOnMaintenance(true);
ds.setAbandonedLogWriter(new PrintWriter(System.err));
}
ds.setValidationQuery("SELECT 1");
ds.setDriverClassName(getDriverClass().getName());
ds.setUsername(user);
ds.setPassword(password);
ds.setUrl(getURL());
return ds;
}