Java Code Examples for com.mchange.v2.c3p0.ComboPooledDataSource#setMaxConnectionAge()
The following examples show how to use
com.mchange.v2.c3p0.ComboPooledDataSource#setMaxConnectionAge() .
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: ConnectionPool.java From streamx with Apache License 2.0 | 6 votes |
public static synchronized ComboPooledDataSource getDatasource(String connectionUrl, String user, String password) { if(dataSources.containsKey(connectionUrl)) { return dataSources.get(connectionUrl); } else { try { ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver cpds.setJdbcUrl(connectionUrl); cpds.setUser(user); cpds.setPassword(password); cpds.setMaxConnectionAge(18000);//5 hours dataSources.put(connectionUrl, cpds); return cpds; } catch (PropertyVetoException e) { log.error("Error while creating c3p0 ComboPooledDataSource" + e); throw new ConnectException(e); } } }
Example 2
Source File: ConnectionPoolManager.java From ezScrum with GNU General Public License v2.0 | 5 votes |
private DataSource createDataSource(String driverClass, String url, String account, String password) { ComboPooledDataSource dataSource = new ComboPooledDataSource(); try { dataSource.setDriverClass(driverClass); dataSource.setJdbcUrl(url); dataSource.setUser(account); dataSource.setPassword(password); dataSource.setMinPoolSize(10); dataSource.setMaxPoolSize(35); dataSource.setAcquireIncrement(0); dataSource.setMaxStatements(0); /** 最大允許的閒置時間(秒) */ dataSource.setMaxIdleTime(300); /** 對閒置的連線進行Query測試設置(秒) */ dataSource.setIdleConnectionTestPeriod(1800); /** Checkin connection時不檢查連線是否有效 */ dataSource.setTestConnectionOnCheckin(false); /** Checkout connection時檢查連線的有效性*/ dataSource.setTestConnectionOnCheckout(true); /** 進行test時使用的 Query設定*/ dataSource.setPreferredTestQuery("SELECT 1;"); /** Connection的最大有效時數(秒)*/ dataSource.setMaxConnectionAge(28800); /** Connection checkout 之後的有效時數(毫秒)*/ dataSource.setCheckoutTimeout(28800000); } catch (PropertyVetoException e) { e.printStackTrace(); } mPoolMap.put(url, dataSource); return dataSource; }