當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicDataSource.setMaxWaitMillis方法代碼示例

本文整理匯總了Java中org.apache.commons.dbcp2.BasicDataSource.setMaxWaitMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDataSource.setMaxWaitMillis方法的具體用法?Java BasicDataSource.setMaxWaitMillis怎麽用?Java BasicDataSource.setMaxWaitMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


在下文中一共展示了BasicDataSource.setMaxWaitMillis方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: init

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@PostConstruct
/**
 * Creates security data-source to be used with the sample DB 
 */
public void init() {
       securityDataSource = new BasicDataSource();
       securityDataSource.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
       securityDataSource.setUrl("jdbc:mysql://localhost:3306/java_one_2014");
       securityDataSource.setUsername("java_one");
       securityDataSource.setPassword("");
	securityDataSource.setInitialSize(5);
       securityDataSource.setMaxTotal(30);
       securityDataSource.setMaxIdle(15);
       securityDataSource.setMaxWaitMillis(3000);
       securityDataSource.setLogAbandoned(true);
       securityDataSource.setTestWhileIdle(true);
       securityDataSource.setTestOnBorrow(true);
       securityDataSource.setValidationQuery("select 1");
}
 
開發者ID:ishaigor,項目名稱:rest-retro-sample,代碼行數:20,代碼來源:PersistenceConfiguration.java

示例4: wrap

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public DataSource wrap(final ReportDataSource rptDs) {
    try {
        final BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(rptDs.getDriverClass());
        dataSource.setUrl(rptDs.getJdbcUrl());
        dataSource.setUsername(rptDs.getUser());
        dataSource.setPassword(rptDs.getPassword());
        dataSource.setInitialSize(MapUtils.getInteger(rptDs.getOptions(), "initialSize", 3));
        dataSource.setMaxIdle(MapUtils.getInteger(rptDs.getOptions(), "maxIdle", 20));
        dataSource.setMinIdle(MapUtils.getInteger(rptDs.getOptions(), "minIdle", 1));
        dataSource.setLogAbandoned(MapUtils.getBoolean(rptDs.getOptions(), "logAbandoned", true));
        dataSource.setRemoveAbandonedTimeout(
            MapUtils.getInteger(rptDs.getOptions(), "removeAbandonedTimeout", 180));
        dataSource.setMaxWaitMillis(MapUtils.getInteger(rptDs.getOptions(), "maxWait", 1000));
        return dataSource;
    } catch (final Exception ex) {
        throw new RuntimeException("C3p0DataSourcePool Create Error", ex);
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:21,代碼來源:DBCP2DataSourcePool.java

示例5: 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

示例6: getPooledDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public static BasicDataSource getPooledDataSource(String connectUrl,
                                             int maxTotal,
                                             int maxWaitTimeMillis) {
  BasicDataSource bds = new BasicDataSource();
  bds.setUrl(connectUrl);
  bds.setMaxTotal(maxTotal);
  bds.setMaxWaitMillis(maxWaitTimeMillis);
  return bds;
}
 
開發者ID:aol,項目名稱:chronos,代碼行數:10,代碼來源:Utils.java

示例7: getDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
protected BasicDataSource getDataSource(String jdbcDriver, String jdbcUrl, String username, String password) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcDriver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setMaxIdle(5);
    dataSource.setMinIdle(1);
    dataSource.setMaxWaitMillis(5000);
    dataSource.setMaxTotal(40);
    dataSource.setInitialSize(10);
    dataSource.setUrl(jdbcUrl);
    return dataSource;
}
 
開發者ID:PkayJava,項目名稱:MBaaS,代碼行數:14,代碼來源:DataSourceFactoryBean.java

示例8: chatDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Bean
public DataSource chatDataSource() throws ConfigurationException, IOException {
	BasicDataSource datasource = new BasicDataSource();
	String path = this.configuration().getString(GlobalConfig.DB_PATH);
	if (path == null) {
		path = GlobalConfig.DB_PATH_DEFAULT;
	}
	datasource.setUsername(this.configuration().getString(GlobalConfig.DB_USERNAME));
	datasource.setPassword(this.configuration().getString(GlobalConfig.DB_PASSWORD));
	datasource.setDriverClassName("org.h2.Driver");
	datasource.setUrl("jdbc:h2:" + path);
	datasource.setMaxIdle(3);
	datasource.setMaxWaitMillis(5000);
	datasource.setRemoveAbandonedOnBorrow(true);
	datasource.setRemoveAbandonedOnBorrow(true);
	datasource.setRemoveAbandonedTimeout(20);
	datasource.setLogAbandoned(true);
	datasource.setValidationQuery("select 1");
	datasource.setMinEvictableIdleTimeMillis(3600000);
	datasource.setTimeBetweenEvictionRunsMillis(1800000);
	datasource.setNumTestsPerEvictionRun(10);
	datasource.setTestOnBorrow(true);
	datasource.setTestOnReturn(false);
	datasource.addConnectionProperty("useUnicode", "yes");
	datasource.addConnectionProperty("characterEncoding", "utf8");
	return datasource;
}
 
開發者ID:shilongdai,項目名稱:LSChatServer,代碼行數:28,代碼來源:ApplicationRootContext.java

示例9: registerDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * register the data source for H2 DB
 *
 * @return pooling database object
 */

private static BasicDataSource registerDataSource() {
    System.setProperty("h2.baseDir", BASE_DIR);

    // create a database connection
    String user = AppConfig.getProperty("dbUser");
    String password = AppConfig.decryptProperty("dbPassword");
    String connectionURL = AppConfig.getProperty("dbConnectionURL");

    if(connectionURL != null && connectionURL.contains("CIPHER=")) {
        password = "filepwd " + password;
    }

    String validationQuery = "select 1";

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(DB_DRIVER);
    dataSource.setMaxTotal(MAX_ACTIVE);
    dataSource.setTestOnBorrow(TEST_ON_BORROW);
    dataSource.setMinIdle(MIN_IDLE);
    dataSource.setMaxWaitMillis(MAX_WAIT);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setUrl(connectionURL);

    return dataSource;

}
 
開發者ID:skavanagh,項目名稱:EC2Box,代碼行數:35,代碼來源:DSPool.java

示例10: 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

示例11: initDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * 指定所有參數連接數據源
 */
private void initDataSource() {
    /**
     * @param connectURI    數據庫
     * @param username      用戶名
     * @param password      密碼
     * @param driverClass   數據庫連接驅動名
     * @param initialSize   初始連接池連接個數
     * @param maxTotal      最大活動連接數
     * @param maxIdle       最大連接數
     * @param maxWaitMillis 獲得連接的最大等待毫秒數
     * @param minIdle       最小連接數
     */
    BasicDataSource basicDataSource = new BasicDataSource();
    String connectURI = System.getProperty("easy.test.base.db.url");
    if (StringUtils.isNotEmpty(connectURI)) {
        connectURI = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&aut";
    }
    basicDataSource.setUrl(connectURI);
    String username = System.getProperty("easy.test.base.db.username");
    if (StringUtils.isNotEmpty(username)) {
        username = "root";
    }
    basicDataSource.setUsername(username);
    String password = System.getProperty("easy.test.base.db.password");
    if (StringUtils.isNotEmpty(password)) {
        password = "";
    }
    basicDataSource.setPassword(password);
    String driverClass = System.getProperty("easy.test.base.db.driver");
    if (StringUtils.isNotEmpty(driverClass)) {
        driverClass = "com.mysql.jdbc.Driver";
    }
    basicDataSource.setDriverClassName(driverClass);
    int initialSize = 5;
    String initialSizeStr = System.getProperty("easy.test.base.db.initSize");
    if (StringUtils.isNotEmpty(initialSizeStr)) {
        initialSize = Integer.parseInt(initialSizeStr);
    }
    basicDataSource.setInitialSize(initialSize); // 初始的連接數;
    int maxTotal = 10;
    String maxTotalStr = System.getProperty("easy.test.base.db.maxTotal");
    if (StringUtils.isNotEmpty(maxTotalStr)) {
        maxTotal = Integer.parseInt(maxTotalStr);
    }
    basicDataSource.setMaxTotal(maxTotal);
    int maxIdle = 5;
    String maxIdleStr = System.getProperty("easy.test.base.db.maxIdle");
    if (StringUtils.isNotEmpty(maxIdleStr)) {
        maxIdle = Integer.parseInt(maxIdleStr);
    }
    basicDataSource.setMaxIdle(maxIdle);
    int maxWaitMillis = 5;
    String maxWaitMillisStr = System.getProperty("easy.test.base.db.maxWaitMillis");
    if (StringUtils.isNotEmpty(maxWaitMillisStr)) {
        maxWaitMillis = Integer.parseInt(maxWaitMillisStr);
    }
    basicDataSource.setMaxWaitMillis(maxWaitMillis);
    int minIdle = 1;
    String minIdleStr = System.getProperty("easy.test.base.db.minIdle");
    if (StringUtils.isNotEmpty(minIdleStr)) {
        minIdle = Integer.parseInt(minIdleStr);
    }
    basicDataSource.setMinIdle(minIdle);
    dataSource = basicDataSource;
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:69,代碼來源:DataBaseMapperImpl.java

示例12: getDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Bean(name = "dataSource")
public DataSource getDataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    String connectURI = System.getProperty("easy.test.base.db.url");
    if (StringUtils.isNotEmpty(connectURI)) {
        connectURI = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&aut";
    }
    basicDataSource.setUrl(connectURI);
    String username = System.getProperty("easy.test.base.db.username");
    if (StringUtils.isNotEmpty(username)) {
        username = "root";
    }
    basicDataSource.setUsername(username);
    String password = System.getProperty("easy.test.base.db.password");
    if (StringUtils.isNotEmpty(password)) {
        password = "";
    }
    basicDataSource.setPassword(password);
    String driverClass = System.getProperty("easy.test.base.db.driver");
    if (StringUtils.isNotEmpty(driverClass)) {
        driverClass = "com.mysql.jdbc.Driver";
    }
    basicDataSource.setDriverClassName(driverClass);
    int initialSize = 5;
    String initialSizeStr = System.getProperty("easy.test.base.db.initSize");
    if (StringUtils.isNotEmpty(initialSizeStr)) {
        initialSize = Integer.parseInt(initialSizeStr);
    }
    basicDataSource.setInitialSize(initialSize); // 初始的連接數;
    int maxTotal = 10;
    String maxTotalStr = System.getProperty("easy.test.base.db.maxTotal");
    if (StringUtils.isNotEmpty(maxTotalStr)) {
        maxTotal = Integer.parseInt(maxTotalStr);
    }
    basicDataSource.setMaxTotal(maxTotal);
    int maxIdle = 5;
    String maxIdleStr = System.getProperty("easy.test.base.db.maxIdle");
    if (StringUtils.isNotEmpty(maxIdleStr)) {
        maxIdle = Integer.parseInt(maxIdleStr);
    }
    basicDataSource.setMaxIdle(maxIdle);
    int maxWaitMillis = 5;
    String maxWaitMillisStr = System.getProperty("easy.test.base.db.maxWaitMillis");
    if (StringUtils.isNotEmpty(maxWaitMillisStr)) {
        maxWaitMillis = Integer.parseInt(maxWaitMillisStr);
    }
    basicDataSource.setMaxWaitMillis(maxWaitMillis);
    int minIdle = 1;
    String minIdleStr = System.getProperty("easy.test.base.db.minIdle");
    if (StringUtils.isNotEmpty(minIdleStr)) {
        minIdle = Integer.parseInt(minIdleStr);
    }
    basicDataSource.setMinIdle(minIdle);
    return basicDataSource;
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:56,代碼來源:DataResourceConfig.java


注:本文中的org.apache.commons.dbcp2.BasicDataSource.setMaxWaitMillis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。