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


Java BasicDataSource.setMinIdle方法代碼示例

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


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

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource createDataSource() {
    final String driverClass = (String) dbConfig.get("javax.persistence.jdbc.driver");
    final String connectionUrl = (String) dbConfig.get("javax.persistence.jdbc.url");
    final String username = (String) dbConfig.get("javax.persistence.jdbc.user");
    final String password = (String) dbConfig.get("javax.persistence.jdbc.password");

    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverClass);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setUrl(connectionUrl);
    ds.setMinIdle(1);
    ds.setMaxIdle(2);

    return ds;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:SqlDbConfiguration.java

示例4: AbstractMysqlHandler

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public AbstractMysqlHandler() throws Exception{
        shardCount = Integer.parseInt(System.getProperty(PROP_SHARD_CNT));
        for(int i=0; i<shardCount; i++){
            final BasicDataSource ds = new BasicDataSource();
            ds.setMaxTotal(1024);
            ds.setMaxIdle(1024);
            ds.setMinIdle(0);
            ds.setUrl(System.getProperty(String.format(PROP_SHARD_URL, i)));
            ds.setUsername(System.getProperty(String.format(PROP_SHARD_USERNAME, i)));
            ds.setPassword(System.getProperty(String.format(PROP_SHARD_PASSWORD, i)));
            dataSourceList.add(ds);
        }
        
//        final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
//        scriptEngine = scriptEngineManager.getEngineByName(SCRIPT_ENGINE_NAME);
//        scriptEngine.eval(System.getProperty(PROP_SCRIPT));
        
    }
 
開發者ID:kakao,項目名稱:adt,代碼行數:19,代碼來源:AbstractMysqlHandler.java

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

示例6: SQLDatabase

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public SQLDatabase(SQLDatabaseType jdbcInfo, String username, String password, String database, String host,
		int port, String key) {

	// TODO: check parameters

	this.jdbcInfo = jdbcInfo;
	this.username = username;
	this.password = password;
	this.host = host;
	this.port = port;
	this.database = database;
	this.key = key;

	BasicDataSource ds = new BasicDataSource();
	String urlPrefix = jdbcInfo.getJDBCurl(this.host, this.database, this.port) + "?autoReconnect=true";
	ds.setUrl(urlPrefix);
	ds.setUsername(username);
	ds.setPassword(password);
	ds.setDriverClassName(jdbcInfo.getDriverName());
	ds.setMinIdle(5);
	ds.setMaxIdle(10);
	ds.setMaxOpenPreparedStatements(100);

	dataSource = ds;
	setValidationQuery();
}
 
開發者ID:rwth-acis,項目名稱:mobsos-query-visualization,代碼行數:27,代碼來源:SQLDatabase.java

示例7: getDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Bean(name = "dataSource")
public DataSource getDataSource(){
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&aut");
    dataSource.setUsername("root");
    dataSource.setPassword("");
    dataSource.setInitialSize(3);
    dataSource.setMinIdle(3);
    dataSource.setMaxIdle(5);
    dataSource.setMaxTotal(10);
    return dataSource;
}
 
開發者ID:easymall,項目名稱:easymall,代碼行數:13,代碼來源:DataResourceConfig.java

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

示例9: createDataSourceMetadata

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private CommonsDbcp2DataSourcePoolMetadata createDataSourceMetadata(int minSize,
		int maxSize) {
	BasicDataSource dataSource = createDataSource();
	dataSource.setMinIdle(minSize);
	dataSource.setMaxTotal(maxSize);
	return new CommonsDbcp2DataSourcePoolMetadata(dataSource);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:8,代碼來源:CommonsDbcp2DataSourcePoolMetadataTests.java

示例10: DataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private DataSource() throws IOException, SQLException, PropertyVetoException {
  LOGGER.info("Creating datasource instance..");
  basicDataSource = new BasicDataSource();
  basicDataSource.setDriverClassName(CONFIG.get("DB_DRIVER_CLASS_NAME"));
  basicDataSource.setUsername(CONFIG.get("DB_USER_NAME"));
  basicDataSource.setPassword(CONFIG.get("DB_PASSWORD"));
  basicDataSource.setUrl(CONFIG.get("DB_URL"));

  // the settings below are optional -- dbcp can work with defaults
  basicDataSource.setMinIdle(CONFIG.getInt("DB_MIN_IDLE"));
  basicDataSource.setMaxIdle(CONFIG.getInt("DB_MAX_IDLE"));
  basicDataSource.setMaxOpenPreparedStatements(CONFIG.getInt("DB_MAX_OPEN_PS"));

}
 
開發者ID:techysoul,項目名稱:java,代碼行數:15,代碼來源:DataSource.java

示例11: setupDataSourcePool

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
protected BasicDataSource setupDataSourcePool( DataSourceConfiguration config )
        throws Exception
{
    BasicDataSource pool = new BasicDataSource();

    Class.forName( config.driver().get() );
    pool.setDriverClassName( config.driver().get() );
    pool.setUrl( config.url().get() );

    if ( !config.username().get().equals( "" ) ) {
        pool.setUsername( config.username().get() );
        pool.setPassword( config.password().get() );
    }

    if ( config.minPoolSize().get() != null ) {
        pool.setMinIdle( config.minPoolSize().get() );
    }
    if ( config.maxPoolSize().get() != null ) {
        pool.setMaxTotal( config.maxPoolSize().get() );
    }
    if ( config.loginTimeoutSeconds().get() != null ) {
        pool.setLoginTimeout( config.loginTimeoutSeconds().get() );
    }
    if ( config.maxConnectionAgeSeconds().get() != null ) {
        pool.setMinEvictableIdleTimeMillis( config.maxConnectionAgeSeconds().get() * 1000 );
    }
    if ( config.validationQuery().get() != null ) {
        pool.setValidationQuery( config.validationQuery().get() );
    }

    return pool;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:34,代碼來源:DBCPDataSourceServiceImporter.java

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

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

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

示例15: build

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {

	final String dataContextId = configurationProperties.getDataContextId().orElse(null);

	final String url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
	if (url == null) {
		throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
				.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
	}

	final String driverClass = configurationProperties.getConfigPropertyValue(
			DataSourceConfigProperties.DRIVER_CLASS_NAME,
			configurationProperties.getDriverClassName()
					.orElseThrow(() -> new ConfigurationException(DefaultDataSourceBuilderConfiguration
							.buildMissingDriverClassMessage(getDataSourceType(), dataContextId))));

	try {
		// specific properties
		Map<String, String> dbcpProperties = configurationProperties.getSubPropertiesUsingPrefix("dbcp");
		Properties poolProperties = new Properties();
		poolProperties.putAll(dbcpProperties);

		BasicDataSource ds = BasicDataSourceFactory.createDataSource(poolProperties);

		ds.setDriverClassName(driverClass);
		ds.setUrl(url);

		// validation query
		configurationProperties.getConnectionValidationQuery().ifPresent(vq -> {
			ds.setTestOnBorrow(true);
			ds.setValidationQuery(vq);
		});

		// credentials
		ds.setUsername(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null));
		ds.setPassword(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null));

		// pool size
		Integer minPoolSize = configurationProperties
				.getConfigPropertyValue(DataSourceConfigProperties.MIN_POOL_SIZE, null);
		if (minPoolSize != null && minPoolSize > 0) {
			ds.setInitialSize(minPoolSize);
			ds.setMinIdle(minPoolSize);
		}

		Integer maxPoolSize = configurationProperties.getConfigPropertyValue(
				DataSourceConfigProperties.MAX_POOL_SIZE, DataSourceConfigProperties.DEFAULT_MAX_POOL_SIZE);
		if (maxPoolSize != null && maxPoolSize > 0) {
			ds.setMaxTotal(maxPoolSize);
			if (ds.getMaxIdle() > maxPoolSize) {
				ds.setMaxIdle(maxPoolSize);
			}
		}

		// autocommit
		if (configurationProperties.isDisableAutoCommit()) {
			ds.setDefaultAutoCommit(Boolean.FALSE);
		}

		LOGGER.debug(() -> "(Data context id: " + dataContextId + "): "
				+ "DBCP2 DataSource setted up for jdbc url: " + url + " [Max pool size: " + maxPoolSize + "]");

		return ds;
	} catch (Exception e) {
		throw new ConfigurationException("Failed to configure [" + getDataSourceType() + "] DataSource", e);
	}
}
 
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:69,代碼來源:DBCP2DataSourceFactory.java


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