// 初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 initialPoolSize
cpds.setInitialPoolSize(Integer.valueOf(p
.getProperty("initialpoolsize")));
// 连接池中保留的最小连接数。
cpds.setMinPoolSize(Integer.valueOf(p.getProperty("minpoolsize")));
// 连接池中保留的最大连接数。Default: 15 maxPoolSize
cpds.setMaxPoolSize(Integer.valueOf(p.getProperty("maxpoolsize")));
// JDBC的标准参数,用以控制数据源内加载的PreparedStatement数据.但由于预缓存的Statement属于单个Connection而不是整个连接池.所以
// 设置这个参数需要考滤到多方面的因素,如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭.默认为0;
cpds.setMaxStatements(Integer.valueOf(p.getProperty("maxstatements")));
// 连接池内单个连接所拥有的最大缓存被关闭.默认为0;
cpds.setMaxStatementsPerConnection(Integer.valueOf(p
.getProperty("maxstatementsperconnection")));
// C3P0是异步操作的,缓慢的JDBC操作通过帮助进程完成.扩展这些操作可以有效的提升性能,通过多数程实现多个操作同时被执行.默为为3
cpds.setNumHelperThreads(Integer.valueOf(p
.getProperty("numhelperthreads")));
// 用户修改系统配置参数执行前最多等待的秒数.默认为300;
cpds.setPropertyCycle(Integer.valueOf(p.getProperty("propertycycle")));
// 如果设为true那么在取得连接的同时将校验连接的有效性。Default: false testConnectionOnCheckin
cpds.setTestConnectionOnCheckin(Boolean.valueOf(p
.getProperty("testconnectiononcheckin")));
// 因性能消耗大请只在需要的时候使用它。
// 如果设为true那么在每个connection提交的时候都将校验其有效性。
// 建议使用idleConnectionTestPeriod或automaticTestTable等方法来提升连接测试的性能。Default:
// false testConnectionOnCheckout
cpds.setTestConnectionOnCheckout(Boolean.valueOf(p
.getProperty("testconnectionOncheckout")));
// 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。
// 但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。
// 如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。Default: false
// breakAfterAcquireFailure
cpds.setBreakAfterAcquireFailure(Boolean.valueOf(p
}
/**
* 获得ConnectionManager单例对象
* @return
*/
public synchronized static ConnectionManager getInstance() {
if (instance == null) {
try {
instance = new ConnectionManager();
} catch (Exception e) {
e.printStackTrace();
}
}
return instance;
}
/**
* 获得连接
* @return
*/
public Connection getContection() {
try {
return cpds.getConnection();
} catch (SQLException e) {
e.printStackTrace();
} www.2cto.com
return null;
}
作者:tbwshc