本文整理匯總了Java中com.alibaba.druid.pool.DruidDataSource.setTimeBetweenEvictionRunsMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java DruidDataSource.setTimeBetweenEvictionRunsMillis方法的具體用法?Java DruidDataSource.setTimeBetweenEvictionRunsMillis怎麽用?Java DruidDataSource.setTimeBetweenEvictionRunsMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.druid.pool.DruidDataSource
的用法示例。
在下文中一共展示了DruidDataSource.setTimeBetweenEvictionRunsMillis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: businessDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
@Primary
public DruidDataSource businessDataSource() throws SQLException, DESException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(dbConfigProperties.getDriveClass());
druidDataSource.setUrl(dbConfigProperties.getBusinessUrl());
druidDataSource.setUsername(dbConfigProperties.getBusinessUsername());
druidDataSource.setPassword(dbConfigProperties.getBusinessPassword());
druidDataSource.setInitialSize(dbConfigProperties.getInitialSize());
druidDataSource.setMinIdle(dbConfigProperties.getMinIdle());
druidDataSource.setMaxActive(dbConfigProperties.getMaxActive());
druidDataSource.setMaxWait(dbConfigProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(dbConfigProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(dbConfigProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(dbConfigProperties.getValidationQuery());//此項如果為空,下麵幾個test都不會生效
druidDataSource.setTestWhileIdle(dbConfigProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(dbConfigProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(dbConfigProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(dbConfigProperties.getPoolPreparedStatements());//5.5以後的mysql開啟,以後的關閉
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(dbConfigProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(dbConfigProperties.getFilters());
return druidDataSource;
}
示例2: logDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource logDataSource() throws SQLException, DESException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(dbConfigProperties.getDriveClass());
druidDataSource.setUrl(dbConfigProperties.getLogUrl());
druidDataSource.setUsername(dbConfigProperties.getLogUsername());
druidDataSource.setPassword(dbConfigProperties.getLogPassword());
druidDataSource.setInitialSize(dbConfigProperties.getInitialSize());
druidDataSource.setMinIdle(dbConfigProperties.getMinIdle());
druidDataSource.setMaxActive(dbConfigProperties.getMaxActive());
druidDataSource.setMaxWait(dbConfigProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(dbConfigProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(dbConfigProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(dbConfigProperties.getValidationQuery());
druidDataSource.setTestWhileIdle(dbConfigProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(dbConfigProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(dbConfigProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(dbConfigProperties.getPoolPreparedStatements());
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(dbConfigProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(dbConfigProperties.getFilters());
return druidDataSource;
}
示例3: userDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
/**
* 使用@Primary注解主數據源
*/
@Bean(name = "userDataSource")
@Primary
public DataSource userDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
//configuration
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
dataSource.setMaxActive(maxActive);
dataSource.setMaxWait(maxWait);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setValidationQuery(validationQuery);
dataSource.setTestWhileIdle(testWhileIdle);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnReturn(testOnReturn);
dataSource.setPoolPreparedStatements(poolPreparedStatements);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
return dataSource;
}
示例4: studentDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(name = "studentDataSource")
public DataSource studentDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(studentUrl);
dataSource.setUsername(studentUser);
dataSource.setPassword(studentPassword);
dataSource.setDriverClassName(studentDriverClass);
//configuration
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
dataSource.setMaxActive(maxActive);
dataSource.setMaxWait(maxWait);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setValidationQuery(validationQuery);
dataSource.setTestWhileIdle(testWhileIdle);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnReturn(testOnReturn);
dataSource.setPoolPreparedStatements(poolPreparedStatements);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
return dataSource;
}
示例5: DataSourceBuilder
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
/**
* new druidDataSource and set config
* @throws Exception
*/
public DataSourceBuilder() throws Exception {
DruidDataSource druidDataSource = new DruidDataSource();
Properties conf = new Properties();
InputStream in = this.getClass().getResourceAsStream("/db_config.properties");
conf.load(in);
in.close();
long maxWait = Long.parseLong(conf.getProperty("druid.maxWait"));
long timeBetweenEvictionRunsMillis = Long.parseLong(conf.getProperty("druid.timeBetweenEvictionRunsMillis"));
druidDataSource.configFromPropety(conf);
druidDataSource.setMaxWait(maxWait);
druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
this.dataSource = druidDataSource;
}
示例6: mafSlaveDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(name = ConfigConstant.NAME_DS_SLAVE)
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_SLAVE)
public DataSource mafSlaveDataSource() {
logger.info("----- MAFIA slave data source INIT -----");
DruidDataSource ds = new DruidDataSource();
try {
ds.setFilters(env.getProperty("ds.filters"));
} catch (SQLException e) {
logger.warn("Data source set filters ERROR:", e);
}
ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
ds.setValidationQuery(env.getProperty("ds.validationQuery"));
ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
return ds;
}
示例7: mafMasterDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(name = ConfigConstant.NAME_DS_MASTER)
@Primary
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_MASTER)
public DataSource mafMasterDataSource() {
logger.info("----- MAFIA master data source INIT -----");
DruidDataSource ds = new DruidDataSource();
try {
ds.setFilters(env.getProperty("ds.filters"));
} catch (SQLException e) {
logger.warn("Data source set filters ERROR:", e);
}
ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
ds.setValidationQuery(env.getProperty("ds.validationQuery"));
ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
return ds;
}
示例8: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource(DruidConfig druidConfig) throws IOException {
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
ds.setUrl(druidConfig.getUrl() + "?" + druidConfig.getOptions());
ds.setUsername(druidConfig.getUser());
ds.setPassword(druidConfig.getPwd());
ds.setInitialSize(druidConfig.getInitialSize());
ds.setMinIdle(druidConfig.getMinIdle());
ds.setMaxActive(druidConfig.getMaxActive());
ds.setMaxWait(druidConfig.getMaxWait());
ds.setTimeBetweenEvictionRunsMillis(druidConfig.getTimeBetweenEvictionRunsMillis());
ds.setMinEvictableIdleTimeMillis(druidConfig.getMinEvictableIdleTimeMillis());
ds.setValidationQuery(druidConfig.getValidationQuery());
ds.setTestWhileIdle(druidConfig.getTestWhileIdle());
ds.setTestOnBorrow(druidConfig.getTestOnBorrow());
ds.setTestOnReturn(druidConfig.getTestOnReturn());
return ds;
}
示例9: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource() throws SQLException {
if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) {
System.out.println("Your database connection pool configuration is incorrect!"
+ " Please check your Spring profile, current profiles are:"
+ Arrays.toString(environment.getActiveProfiles()));
throw new ApplicationContextException(
"Database connection pool is not configured correctly");
}
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
druidDataSource.setUrl(propertyResolver.getProperty("url"));
druidDataSource.setUsername(propertyResolver.getProperty("username"));
druidDataSource.setPassword(propertyResolver.getProperty("password"));
druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait")));
druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis")));
druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery"));
druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle")));
druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow")));
druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn")));
druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements")));
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize")));
druidDataSource.setFilters(propertyResolver.getProperty("filters"));
return druidDataSource;
}
示例10: masterDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setName("master");
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
// 配置初始化大小、最小、最大
dataSource.setInitialSize(0);
dataSource.setMinIdle(0);
dataSource.setMaxActive(10);
// 配置獲取連接等待超時的時間
dataSource.setMaxWait(15000);
// 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒
dataSource.setTimeBetweenEvictionRunsMillis(60000);
// 配置一個連接在池中最小生存的時間,一個小時
dataSource.setMinEvictableIdleTimeMillis(3600000);
dataSource.setTestWhileIdle(true);
// 這裏建議配置為TRUE,防止取到的連接不可用
dataSource.setTestOnBorrow(true);
dataSource.setTestOnReturn(false);
// 這裏配置提交方式,默認就是TRUE,可以不用配置
dataSource.setDefaultAutoCommit(true);
// 驗證連接有效與否的SQL,不同的數據配置不同
dataSource.setValidationQuery("SELECT 1");
return dataSource;
}
開發者ID:zheng-zy,項目名稱:springboot-mybatis-druid-mutil-datasource,代碼行數:30,代碼來源:MasterDataSourceConfig.java
示例11: register
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Override
public boolean register() {
if (IsRegistered) {
return HAS_REGISTERED;
}
DruidDataSource ds = new DruidDataSource();
if (!StrUtil.isBlank(name)) {
ds.setName(this.name);
}
ds.setUrl(jdbcURL);
ds.setDriverClassName(jdbcDriver);
ds.setUsername(jdbcUsername);
ds.setPassword(jdbcPassword);
ds.setMinIdle(minIdle);
ds.setMaxActive(maxActive);
ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
ds.setValidationQuery(validationQuery);
ds.setTestWhileIdle(testWhileIdle);
ds.setTestOnBorrow(testOnBorrow);
ds.setTestOnReturn(testOnReturn);
setDataSource(ds);
setIsRegistered(HAS_REGISTERED);
return HAS_REGISTERED;
}
示例12: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean //聲明其為Bean實例
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
System.err.println("druid configuration initialization filter: "+ e);
}
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
示例13: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public DataSource dataSource() throws SQLException {
if (StringUtils.isEmpty(datasourcePropertyResolver.getProperty("url"))) {
System.out.println("Your database connection pool configuration is incorrect!" +
" Please check your Spring profile, current profiles are:"+
Arrays.toString(environment.getActiveProfiles()));
throw new ApplicationContextException(
"Database connection pool is not configured correctly");
}
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl(datasourcePropertyResolver.getProperty("url"));
druidDataSource.setUsername(datasourcePropertyResolver
.getProperty("username"));
druidDataSource.setPassword(datasourcePropertyResolver
.getProperty("password"));
druidDataSource.setInitialSize(1);
druidDataSource.setMinIdle(1);
druidDataSource.setMaxActive(20);
druidDataSource.setMaxWait(60000);
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
druidDataSource.setMinEvictableIdleTimeMillis(300000);
druidDataSource.setValidationQuery("SELECT 'x'");
druidDataSource.setTestWhileIdle(true);
druidDataSource.setTestOnBorrow(false);
druidDataSource.setTestOnReturn(false);
return druidDataSource;
}
示例14: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
System.err.println("druid configuration initialization filter: " + e);
}
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
示例15: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
if(initialSize != null) {
datasource.setInitialSize(initialSize);
}
if(minIdle != null) {
datasource.setMinIdle(minIdle);
}
if(maxActive != null) {
datasource.setMaxActive(maxActive);
}
if(maxWait != null) {
datasource.setMaxWait(maxWait);
}
if(timeBetweenEvictionRunsMillis != null) {
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
if(minEvictableIdleTimeMillis != null) {
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
if(validationQuery!=null) {
datasource.setValidationQuery(validationQuery);
}
if(testWhileIdle != null) {
datasource.setTestWhileIdle(testWhileIdle);
}
if(testOnBorrow != null) {
datasource.setTestOnBorrow(testOnBorrow);
}
if(testOnReturn != null) {
datasource.setTestOnReturn(testOnReturn);
}
if(poolPreparedStatements != null) {
datasource.setPoolPreparedStatements(poolPreparedStatements);
}
if(maxPoolPreparedStatementPerConnectionSize != null) {
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
}
if(connectionProperties != null) {
datasource.setConnectionProperties(connectionProperties);
}
List<Filter> filters = new ArrayList<>();
filters.add(statFilter());
filters.add(wallFilter());
datasource.setProxyFilters(filters);
return datasource;
}