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


Java BasicDataSource.setMaxIdle方法代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.BasicDataSource.setMaxIdle方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setMaxIdle方法的具体用法?Java BasicDataSource.setMaxIdle怎么用?Java BasicDataSource.setMaxIdle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


在下文中一共展示了BasicDataSource.setMaxIdle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

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

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

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

示例10: pgDataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Bean
@Nonnull
public DataSource pgDataSource() throws SQLException {
    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(env.getProperty("db.driver"));
    ds.setUrl(env.getRequiredProperty("db.url"));
    ds.setUsername(env.getRequiredProperty("db.username"));
    ds.setPassword(env.getRequiredProperty("db.password"));
    ds.setInitialSize(env.getProperty("db.initialSize", Integer.class, 8));
    ds.setMaxTotal(env.getProperty("db.maxSize", Integer.class, 48));
    ds.setMaxIdle(env.getProperty("db.minIdle", Integer.class, 4));
    return ds;
}
 
开发者ID:andrewortman,项目名称:reddcrawl,代码行数:14,代码来源:PersistenceConfiguration.java

示例11: setupDataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource setupDataSource(String server, int port, String dbName,
                                               String username,
                                               String password, int maxActive, int maxIdle) {
    Preconditions.checkNotNull(server);
    Preconditions.checkNotNull(dbName);
    Preconditions.checkNotNull(username);

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername(username);

    if (password.length() > 0) {
        ds.setPassword(password);
    }

    String
            url =
            String.format("jdbc:mysql://%s:%d/%s?useConfigs=maxPerformance&useCompression=true",
                          server, port, dbName);
    ds.setUrl(url);
    ds.setValidationQuery("SELECT 1;");
    ds.setTestWhileIdle(true);
    ds.setTestOnReturn(true);
    ds.setMaxTotal(maxActive);
    ds.setMaxIdle(maxIdle);
    ds.setRemoveAbandonedOnBorrow(true);
    ds.setRemoveAbandonedTimeout(60);

    if (Configuration.getInstance().isDeveloperMode()) {
        ds.setLogAbandoned(true);
    }

    sLogger.info("created new Connectionpool");
    return ds;
}
 
开发者ID:anycook,项目名称:anycook-api,代码行数:36,代码来源:DBHandler.java

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

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

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

示例15: DatabaseConnectionFactory

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
private DatabaseConnectionFactory() {
	logger.debug("Creating new Database Connection Factory ...");
	PropertiesFactory pf = PropertiesFactory.getInstance();
	
	String pathToConfigDir = pf.getConfigDir();
	try {
		config = new PropertiesConfiguration(pathToConfigDir + "/database.properties");

		// Set the user name and password.
		String userName = config.getString("database.username");
		String password = config.getString("database.password");
		int minidle = config.getInt("database.connection.min", 3);
		int maxIdle = config.getInt("database.connection.maxIdle", 40);
		int max = config.getInt("database.connection.max", 50);
		int evictor = config.getInt("database.connection.evictor.millis", 500);
		int timeout = config.getInt("database.connection.timeout", 120);
		Boolean autoCommit = config.getBoolean("database.connection.autoCommit", true);
		String url = config.getString("database.url");
		databaseProperties = config.getBoolean("database.configuration.enabled", false);
		
        ds = new BasicDataSource();
        ds.setDriverClassName(config.getString("database.driver"));
        ds.setUsername(userName);
        ds.setPassword(password);
        ds.setUrl(url);
        ds.setDefaultQueryTimeout(timeout);
        //ds.setEnableAutoCommitOnReturn(true);
        ds.setMinIdle(minidle);
        ds.setMaxIdle(maxIdle);
        ds.setTimeBetweenEvictionRunsMillis(evictor);
        ds.setMaxTotal(max);
        //ds.setTimeBetweenEvictionRunsMillis(500);
        ds.setDefaultAutoCommit(autoCommit);
        //ds.setMaxWaitMillis(2000);
		
		// conn = ds.getConnection();
		
		
	} catch (ConfigurationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
 
开发者ID:sgrotz,项目名称:myopentrader,代码行数:45,代码来源:DatabaseConnectionFactory.java


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