java - C3P0 池已满而不是结帐超时
问题描述
C3P0 连接池已满而不是获取 SQL 签出超时异常。我将 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;
}
}
解决方案
推荐阅读
- html - 新行 \n 在 MongoDB Atlas 中不起作用
- java - 为什么 TableView 不显示 JSON 数组?
- javascript - Passport.js Google 注销用户仍然存在
- javascript - 删除一对括号中包含的所有内容,包括括号本身,以防它们包含特定的子字符串
- php - Laravel如何实现从购物车中删除商品的功能?
- google-chrome - 如何更改覆盖新选项卡的 chrome 扩展的优先级
- python - 涉及范围时如何验证用户输入?
- python - 尝试使用 python lxml 对多个元素执行 xpath 时出现奇怪的结果
- python - 在 wagtail 管理主页上自定义页面等待审核面板
- django - 与 Django 的 postgresql 数据库上不存在关系