List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxWait
public synchronized void setMaxWait(long maxWait)
From source file:com.lawulu.bdc.etl.batch.config.DatabaseConfiguration.java
@Bean(destroyMethod = "close") public DataSource dbcpDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setMaxActive(20);//www . j a v a2s . c o m dataSource.setMaxIdle(20); dataSource.setMaxWait(10000); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1"); dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dataSource; }
From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java
public void contextInitialized(final ServletContextEvent arg0) { Properties poolProp = new Properties(); try {//from w ww.ja v a 2 s . co m Context initContext = new InitialContext(); // load pool properties file (from class path) poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties")); StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST")); // process all properties files list in pool properties (from class // path) while (stk.hasMoreTokens()) { try { String propName = stk.nextToken(); LOGGER.info(this, "loading jdbc properties - " + propName); Properties prop = new Properties(); prop.load(ConnectionListener.class.getResourceAsStream(propName)); DataSource dsr; if (prop.containsKey("JNDI_NAME")) { // lookup DataSource from JNDI // FIXME JNDI support is not tested yet. SPI or Factory // is needed here. LOGGER.warn(this, "JNDI DataSource support needs more hands on!"); dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME")); } else { // create new BasicDataSource BasicDataSource bds = new BasicDataSource(); bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE"))); bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE"))); bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT"))); bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL"))); bds.setDriverClassName(prop.getProperty("CLASS_NAME")); bds.setUrl(prop.getProperty("URL")); bds.setUsername(prop.getProperty("USER")); bds.setPassword(prop.getProperty("PASSWORD")); bds.setValidationQuery(prop.getProperty("VALIDATION")); dsr = bds; } boundDsrs.put(prop.getProperty("POOL_NAME"), dsr); initContext.bind(prop.getProperty("POOL_NAME"), dsr); } catch (RuntimeException e) { LOGGER.trace(e); } } } catch (IOException | NamingException e) { LOGGER.trace(e); } }
From source file:com.alibaba.druid.benckmark.pool.Case3.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w .j a v a2 s .com dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setMinIdle(minIdle); 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.setConnectionProperties(connectionProperties); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } // dataSource.close(); System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.CaseKylin_mysql.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from w w w. j a v a 2s . c om*/ 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, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.CaseKylin_Oracle.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);// w ww. j a v a2 s .c o m dataSource.setMaxIdle(maxIdle); dataSource.setMinIdle(minIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(oracleDriverClass); 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); dataSource.setValidationQuery(validateQuery); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.mmnaseri.dragonfly.sample.Config.java
@Bean public DataSource dataSource(DatabaseDialect dialect, @Value("${db.username}") String username, @Value("${db.password}") String password, @Value("${db.database}") String database) { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(dialect.getDriverClassName()); dataSource.setUrl("jdbc:mysql://localhost/" + database); dataSource.setUsername(username);/*from w w w . ja va 2 s. c o m*/ dataSource.setPassword(password); dataSource.setMaxActive(200); dataSource.setMaxIdle(100); dataSource.setMaxWait(1500); return dataSource; }
From source file:fr.gouv.diplomatie.applitutoriel.integration.conf.DataSourceConf.java
@Bean public DataSource dataSource() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url);//from w w w .jav a 2s .co m dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestWhileIdle(testWhileIdle); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); dataSource.setRemoveAbandoned(removeAbandoned); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setLogAbandoned(logAbandoned); return dataSource; }
From source file:$.DataSourceConf.java
@Bean public DataSource dataSource() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url);/* w w w . j a v a 2 s . com*/ dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestWhileIdle(testWhileIdle); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); dataSource.setRemoveAbandoned(removeAbandoned); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setLogAbandoned(logAbandoned); return dataSource; }
From source file:com.tedexis.commons.db.DBSinglePool.java
/** * Crea el pool de conexiones/*from w ww . j a va 2s.c om*/ * * @param configurationDB * @return * @throws ClassNotFoundException */ private BasicDataSource getBasicDataSource(ConfigurationDB configurationDB) throws ClassNotFoundException { BasicDataSource ds = null; if (dataSource == null) { ds = new BasicDataSource(); Class.forName(configurationDB.driverClass); ds.setUrl(configurationDB.url); ds.setDriverClassName(configurationDB.driverClass); ds.setUsername(configurationDB.user); ds.setPassword(configurationDB.password); ds.setInitialSize(configurationDB.poolSize); ds.setMaxActive(configurationDB.poolMaxAct); ds.setMaxIdle(configurationDB.poolMaxIdle); ds.setMaxWait(configurationDB.poolWait); return ds; } return dataSource; }
From source file:com.google.gerrit.server.schema.DataSourceProvider.java
private DataSource open(final SitePaths site, final Config cfg, final Context context, final DataSourceType dst) { ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = dbs.optional("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();//from ww w.j a va2s . co m } String url = dbs.optional("url"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = dbs.optional("username"); String password = dbs.optional("password"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = cfg.getBoolean("database", "connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(cfg.getInt("database", "poollimit", 8)); ds.setMinIdle(cfg.getInt("database", "poolminidle", 4)); ds.setMaxIdle(cfg.getInt("database", "poolmaxidle", 4)); ds.setMaxWait(ConfigUtil.getTimeUnit(cfg, "database", null, "poolmaxwait", MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); ds.setInitialSize(ds.getMinIdle()); return ds; } else { // Don't use the connection pool. // try { final Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return new SimpleDataSource(p); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } } }