示例#1
0
  public void druid() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnBorrow(testWhileIdle);
    dataSource.setTestOnBorrow(testOnReturn);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);

    for (int i = 0; i < TEST_COUNT; ++i) {
      p0(dataSource, "druid", threadCount);
    }
    System.out.println();
  }
  /**
   * 配置数据源
   *
   * @param ds
   * @return
   * @throws SQLException
   */
  @Bean(initMethod = "init", destroyMethod = "close")
  public DataSource dataSource(DruidSettings ds) {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl(ds.getUrl());
    dataSource.setUsername(ds.getUsername());
    dataSource.setPassword(ds.getPassword());
    dataSource.setInitialSize(ds.getInitialSize());
    dataSource.setMaxActive(ds.getMaxActive());
    dataSource.setMinIdle(ds.getMinIdle());
    dataSource.setMaxWait(ds.getMaxWait());
    dataSource.setValidationQuery(ds.getValidationQuery());
    dataSource.setTimeBetweenEvictionRunsMillis(ds.getTimeBetweenEvictionRunsMillis());
    dataSource.setMinEvictableIdleTimeMillis(ds.getMinEvictableIdleTimeMillis());
    dataSource.setTestWhileIdle(ds.isTestWhileIdle());
    dataSource.setTestOnBorrow(ds.isTestOnBorrow());
    dataSource.setTestOnReturn(ds.isTestOnReturn());
    dataSource.setPoolPreparedStatements(ds.isPoolPreparedStatements());
    dataSource.setMaxOpenPreparedStatements(ds.getMaxOpenPreparedStatements());

    try {
      dataSource.setFilters(ds.getFilters());
    } catch (SQLException e) {
      e.printStackTrace();
      LOGGER.error("init druid source error", e);
    }

    LOGGER.debug("init druid source");
    return dataSource;
  }
示例#3
0
  protected void setUp() throws Exception {
    DruidDataSourceStatManager.cear();

    dataSource = new DruidDataSource();
    dataSource.setRemoveAbandoned(true);
    dataSource.setRemoveAbandonedTimeoutMillis(100);
    dataSource.setLogAbandoned(true);
    dataSource.setTimeBetweenEvictionRunsMillis(10);
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    dataSource.setUrl("jdbc:mock:xxx");
  }
 public void init() throws SQLException {
   druidDataSource = new DruidDataSource();
   //		druidDataSource.setDriverClassName(driver);
   druidDataSource.setOracle(false);
   druidDataSource.setUrl(url);
   druidDataSource.setUsername(username);
   druidDataSource.setPassword(password);
   druidDataSource.setMaxActive(maxActive);
   druidDataSource.setMinIdle(minIdle);
   druidDataSource.setInitialSize(initialSize);
   //		 配置获取连接等待超时的时间。 单位是毫秒
   druidDataSource.setMaxWait(3000);
   //		配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
   druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
   //		 配置一个连接在池中最小生存的时间,单位是毫秒
   druidDataSource.setMinEvictableIdleTimeMillis(300000);
   //		打开PSCache,并且指定每个连接上PSCache的大小
   druidDataSource.setPoolPreparedStatements(false);
   druidDataSource.setTestOnBorrow(false);
   druidDataSource.setTestWhileIdle(true);
   druidDataSource.setValidationQuery("SELECT 'x'");
   druidDataSource.init();
 }
  protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();

    driver = new MockDriver();

    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(10); // 180 / 10
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat");
    dataSource.setPoolPreparedStatements(false);
    dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);

    //        ((StatFilter) dataSource.getProxyFilters().get(0)).setMaxSqlStatCount(100);
  }
示例#6
0
  protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();

    driver = new MockDriver();

    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000); // 180 / 10
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat,trace");

    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
  }