Java Code Examples for com.alibaba.druid.pool.DruidDataSource#setConnectionErrorRetryAttempts()

The following examples show how to use com.alibaba.druid.pool.DruidDataSource#setConnectionErrorRetryAttempts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDBCTransactionStore.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public boolean load() {
    try {
        druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(messageStoreConfig.getJdbcDriverClass());
        druidDataSource.setUrl(messageStoreConfig.getJdbcURL());
        druidDataSource.setUsername(messageStoreConfig.getJdbcUser());
        druidDataSource.setPassword(messageStoreConfig.getJdbcPassword());
        druidDataSource.setInitialSize(5);
        druidDataSource.setMaxActive(10);
        druidDataSource.setMinIdle(5);
        druidDataSource.setMaxWait(2000);
        druidDataSource.setMinEvictableIdleTimeMillis(300000);
        druidDataSource.setUseUnfairLock(true);
        druidDataSource.setConnectionErrorRetryAttempts(3);
        druidDataSource.setValidationQuery("SELECT 'x'");
        druidDataSource.setTestOnReturn(false);
        druidDataSource.setTestOnBorrow(false);
        druidDataSource.init();
        return true;
    } catch (Exception e) {
        log.info("druidDataSource load Exeption", e);
        return false;
    }
}
 
Example 2
Source File: DynamicDBUtil.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 获取数据源【最底层方法,不要随便调用】
 *
 * @param dbSource
 * @return
 */
private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {
    DruidDataSource dataSource = new DruidDataSource();

    String driverClassName = dbSource.getDbDriver();
    String url = dbSource.getDbUrl();
    String dbUser = dbSource.getDbUsername();
    String dbPassword = dbSource.getDbPassword();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(url);
    //dataSource.setValidationQuery("SELECT 1 FROM DUAL");
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setBreakAfterAcquireFailure(true);
    dataSource.setConnectionErrorRetryAttempts(0);
    dataSource.setUsername(dbUser);
    dataSource.setMaxWait(60000);
    dataSource.setPassword(dbPassword);

    log.info("******************************************");
    log.info("*                                        *");
    log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*");
    log.info("*                                        *");
    log.info("******************************************");
    return dataSource;
}
 
Example 3
Source File: DynamicDBUtil.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取数据源【最底层方法,不要随便调用】
 *
 * @param dbSource
 * @return
 */
private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {
    DruidDataSource dataSource = new DruidDataSource();

    String driverClassName = dbSource.getDbDriver();
    String url = dbSource.getDbUrl();
    String dbUser = dbSource.getDbUsername();
    String dbPassword = dbSource.getDbPassword();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(url);
    //dataSource.setValidationQuery("SELECT 1 FROM DUAL");
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setBreakAfterAcquireFailure(true);
    dataSource.setConnectionErrorRetryAttempts(0);
    dataSource.setUsername(dbUser);
    dataSource.setMaxWait(60000);
    dataSource.setPassword(dbPassword);

    log.info("******************************************");
    log.info("*                                        *");
    log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*");
    log.info("*                                        *");
    log.info("******************************************");
    return dataSource;
}
 
Example 4
Source File: DruidDatasourceProvider.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JdbcDataSource createDataSource(DatasourceRootConfig.DatasourceConfig config) {
  String username = config.getUser();
  String password = config.getPassword();
  String url = config.getUrl();
  String dbType = config.getDbType();
  int maxRetryCount = config.getMaxRetryCount();
  List<String> initSQLs = config.getInitSqls();

  int maxCon = config.getMaxCon();
  int minCon = config.getMinCon();

  DruidDataSource datasource = new DruidDataSource();
  datasource.setPassword(password);
  datasource.setUsername(username);
  datasource.setUrl(url);
  datasource.setMaxWait(TimeUnit.SECONDS.toMillis(1));
  datasource.setMaxActive(maxCon);
  datasource.setMinIdle(minCon);

  if (maxRetryCount > 0) {
    datasource.setConnectionErrorRetryAttempts(maxRetryCount);
  }
  if (dbType != null) {
    datasource.setDbType(dbType);
  }
  if (initSQLs != null) {
    datasource.setConnectionInitSqls(initSQLs);
  }

  return new JdbcDataSource(config,datasource);
}
 
Example 5
Source File: DruidProperties.java    From spring-boot-starter-dao with Apache License 2.0 4 votes vote down vote up
public DruidDataSource createDataSource() throws SQLException {
	DruidDataSource dataSource = new DruidDataSource();
	dataSource.setUrl(url);
	dataSource.setUsername(username);
	dataSource.setPassword(password);
	dataSource.setDriverClassName(driverClassName);
	dataSource.setConnectProperties(connectProperties);
	dataSource.setInitialSize(initialSize);
	dataSource.setMinIdle(minIdle);
	dataSource.setMaxActive(maxActive);
	dataSource.setMaxWait(maxWait);
	dataSource.setFilters(filters);
	dataSource.setDefaultAutoCommit(defaultAutoCommit);
	dataSource.setTimeBetweenConnectErrorMillis(timeBetweenConnectErrorMillis);
	dataSource.setValidationQuery(validationQuery);
	dataSource.setValidationQueryTimeout(validationQueryTimeout);
	dataSource.setTestWhileIdle(testWhileIdle);
	dataSource.setTestOnBorrow(testOnBorrow);
	dataSource.setTestOnReturn(testOnReturn);
	dataSource.setPoolPreparedStatements(poolPreparedStatements);
	dataSource.setClearFiltersEnable(clearFiltersEnable);
	dataSource.setDefaultReadOnly(defaultReadOnly);
	dataSource.setAsyncCloseConnectionEnable(asyncCloseConnectionEnable);
	dataSource.setConnectionErrorRetryAttempts(connectionErrorRetryAttempts);
	dataSource.setBreakAfterAcquireFailure(breakAfterAcquireFailure);
	dataSource.setDupCloseLogEnable(dupCloseLogEnable);
	dataSource.setEnable(enable);
	dataSource.setLogAbandoned(logAbandoned);
	dataSource.setLogDifferentThread(logDifferentThread);
	dataSource.setLoginTimeout(loginTimeout);
	dataSource.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
	dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
	dataSource.setQueryTimeout(queryTimeout);
	dataSource.setFailFast(failFast);
	dataSource.setMaxCreateTaskCount(maxCreateTaskCount);
	dataSource.setRemoveAbandoned(removeAbandoned);
	dataSource.setRemoveAbandonedTimeoutMillis(removeAbandonedTimeoutMillis);
	dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
	dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
	dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
	dataSource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
	dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
	dataSource.setNotFullTimeoutRetryCount(notFullTimeoutRetryCount);
	dataSource.setTimeBetweenLogStatsMillis(timeBetweenLogStatsMillis);
	return dataSource;
}