List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxOpenPreparedStatements
public synchronized void setMaxOpenPreparedStatements(int maxOpenStatements)
Sets the value of the #maxOpenPreparedStatements property.
Note: this method currently has no effect once the pool has been initialized.
From source file:com.alibaba.druid.pool.DBCPTest.java
public void test_dbcp() throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(MockDriver.class.getName()); dataSource.setUrl("jdbc:mock:xxx"); dataSource.setMaxOpenPreparedStatements(100); dataSource.setPoolPreparedStatements(true); final String sql = "selelct 1"; {//from w w w . ja va 2 s .com Connection conn = dataSource.getConnection(); CallableStatement stmt = conn.prepareCall(sql); stmt.close(); conn.close(); } { Connection conn = dataSource.getConnection(); CallableStatement stmt = conn.prepareCall(sql); stmt.close(); conn.close(); } }
From source file:com.alibaba.druid.pool.bonecp.TestPSCache.java
public void f_test_dbcp() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setUrl("jdbc:mock:test"); ds.setMaxIdle(10);/*from w ww. j av a 2s. c om*/ ds.setPoolPreparedStatements(true); ds.setMaxOpenPreparedStatements(10); for (int i = 0; i < 10; ++i) { f(ds, 5); System.out.println("--------------------------------------------"); } }
From source file:jp.go.nict.langrid.serviceexecutor.db.ConnectionManager.java
private void initWithBasicDataSource(String driverClassName, String connectionUrl, String userName, String password, int maxActive, int maxIdle, int maxWait, int maxPSActive) { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(driverClassName); bds.setUrl(connectionUrl);/*from ww w . j av a 2 s . co m*/ bds.setUsername(userName); bds.setPassword(password); bds.setMaxActive(maxActive); bds.setMaxIdle(maxIdle); bds.setMaxWait(maxWait); if (maxPSActive != -1) { bds.setMaxOpenPreparedStatements(maxPSActive); } this.dataSource = bds; }
From source file:com.emc.ecs.sync.service.MySQLDbService.java
@Override protected JdbcTemplate createJdbcTemplate() { BasicDataSource ds = new BasicDataSource(); ds.setUrl(connectString);//from w w w .j a va 2 s. co m ds.addConnectionProperty("characterEncoding", "UTF-8"); if (username != null) ds.setUsername(username); if (password != null) ds.setPassword(password); ds.setMaxActive(1000); ds.setMaxIdle(1000); ds.setMaxOpenPreparedStatements(1000); ds.setPoolPreparedStatements(true); return new JdbcTemplate(ds); }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setMaxActive(maxActive);/*from w w w . ja v a 2 s . co m*/ dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(preparedStatementCache); dataSource.setMaxOpenPreparedStatements(preparedStatementCacheSize); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setConnectionProperties(properties); // printAV_INFO(dataSource); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from w w w.j av a 2 s . c o m*/ dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.emc.ecs.sync.source.AtmosSource.java
@Override public void parseCustomOptions(CommandLine line) { AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri); endpoints = atmosUri.endpoints;//w ww. ja v a2s . co m uid = atmosUri.uid; secret = atmosUri.secret; namespaceRoot = atmosUri.rootPath; if (line.hasOption(SOURCE_OIDLIST_OPTION)) oidFile = line.getOptionValue(SOURCE_OIDLIST_OPTION); if (line.hasOption(SOURCE_NAMELIST_OPTION)) nameFile = line.getOptionValue(SOURCE_NAMELIST_OPTION); if (line.hasOption(SOURCE_SQLQUERY_OPTION)) { query = line.getOptionValue(SOURCE_SQLQUERY_OPTION); // Initialize a connection pool BasicDataSource ds = new BasicDataSource(); ds.setUrl(line.getOptionValue(JDBC_URL_OPT)); if (line.hasOption(JDBC_DRIVER_OPT)) ds.setDriverClassName(line.getOptionValue(JDBC_DRIVER_OPT)); ds.setUsername(line.getOptionValue(JDBC_USER_OPT)); ds.setPassword(line.getOptionValue(JDBC_PASSWORD_OPT)); ds.setMaxActive(200); ds.setMaxOpenPreparedStatements(180); setDataSource(ds); } deleteTags = line.hasOption(DELETE_TAGS_OPT); }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * //from w w w . j av a 2s . c om * * @return time taken * @throws SQLException */ private long singleDBCP() throws SQLException { // Start DBCP BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); cpds.setMaxOpenPreparedStatements(max_statement); cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); cpds.getConnection(); // call to initialize possible lazy structures etc long start = System.currentTimeMillis(); for (int i = 0; i < MAX_CONNECTIONS; i++) { Connection conn = cpds.getConnection(); conn.close(); } long end = (System.currentTimeMillis() - start); // System.out.println("DBCP Single thread benchmark: "+end); cpds.close(); return end; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * Benchmarks PreparedStatement functionality (single thread) * @return result//from ww w . j a v a2 s .com * * @throws PropertyVetoException * @throws SQLException */ private long testPreparedStatementSingleThreadDBCP() throws PropertyVetoException, SQLException { BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); cpds.setPoolPreparedStatements(true); cpds.setMaxOpenPreparedStatements(30); cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); Connection conn = cpds.getConnection(); long start = System.currentTimeMillis(); for (int i = 0; i < MAX_CONNECTIONS; i++) { Statement st = conn.prepareStatement(TEST_QUERY); st.close(); } conn.close(); long end = (System.currentTimeMillis() - start); System.out.println("DBCP PreparedStatement Single thread benchmark: " + end); results.add("DBCP, " + end); // dispose of pool cpds.close(); return end; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * /*from ww w. j a va 2 s . c o m*/ * * @param doPreparedStatement * @return time taken * @throws PropertyVetoException * @throws InterruptedException * @throws SQLException */ private DataSource multiThreadedDBCP(boolean doPreparedStatement) throws PropertyVetoException, InterruptedException, SQLException { BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); if (doPreparedStatement) { cpds.setPoolPreparedStatements(true); cpds.setMaxOpenPreparedStatements(max_statement); } cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); return cpds; }