问题描述
C3P0 连接池已满比获取 sql Checkout 超时 例外。我已将 ComboPooledDataSource 的最大池大小设置为 600 (comboPooledDataSource.setMaxPoolSize(600)),而在数据库中看到大部分连接处于睡眠模式时。 由于此服务器处于挂起模式。请提出任何解决方案。
public class C3P0DataSource {
private static Logger logger = Logger.getLogger(C3P0DataSource.class);
private static C3P0DataSource dataSource;
private ComboPooledDataSource comboPooledDataSource;
private C3P0DataSource() {
try {
if (comboPooledDataSource == null) {
comboPooledDataSource = new ComboPooledDataSource();
String driver = "com.microsoft.sqlserver.jdbc.sqlServerDriver";
String url = "jdbc:sqlserver://X.X.X.X:1433;databasename=XXXXXX;sendStringParametersAsUnicode=false";
String username = "XXXXX";
String password = "XXXXXXX";
comboPooledDataSource.setDriverClass(driver); // loads the jdbc
// driver
comboPooledDataSource.setJdbcUrl(url);
comboPooledDataSource.setUser(username);
comboPooledDataSource.setPassword(password);
// comboPooledDataSource.setIdleConnectionTestPeriod(60);
comboPooledDataSource.setPreferredTestQuery("select 2");
comboPooledDataSource.setMinPoolSize(10);
comboPooledDataSource.setAcquireIncrement(5);
comboPooledDataSource.setMaxPoolSize(600);
comboPooledDataSource.setMaxIdleTime(30);
// comboPooledDataSource.setMaxIdleTimeExcessConnections(100);
comboPooledDataSource.setAutoCommitOnClose(true);
// comboPooledDataSource.setCheckoutTimeout(30000);
}
} catch (PropertyVetoException ex1) {
}
}
public static C3P0DataSource getInstance() {
if (dataSource == null) {
dataSource = new C3P0DataSource();
logger.info("new object has been created of C3P0DataSource in C3P0DataSource class");
}
return dataSource;
}public Connection getConnection() {
try {
return comboPooledDataSource.getConnection();
} catch (sqlException e) {
}
return null;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)