当前位置: 首页>>代码示例>>Java>>正文


Java BasicDataSource.setRemoveAbandonedOnMaintenance方法代码示例

本文整理汇总了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;
}
 
开发者ID:liuyangming,项目名称:ByteTCC-sample,代码行数:24,代码来源:ConsumerConfig.java

示例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;
}
 
开发者ID:liuyangming,项目名称:ByteTCC-sample,代码行数:24,代码来源:ProviderConfig.java

示例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;
	}
 
开发者ID:granpanda,项目名称:autheo,代码行数:20,代码来源:Autheo.java

示例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();
}
 
开发者ID:statsbiblioteket,项目名称:licensemodule,代码行数:21,代码来源:LicenseModuleStorage.java

示例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();
}
 
开发者ID:rwth-acis,项目名称:mobsos-data-processing,代码行数:40,代码来源:SQLDatabase.java

示例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;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:59,代码来源:DbConnPostgreSQL.java


注:本文中的org.apache.commons.dbcp2.BasicDataSource.setRemoveAbandonedOnMaintenance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。