本文整理汇总了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;
}