当前位置: 首页>>代码示例>>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;未经允许,请勿转载。