首页 > 解决方案 > 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;
        }
    }

标签: javasqlc3p0

解决方案


推荐阅读