ComboPooledDataSource返回的连接没有响应

时间:2015-04-15 05:59:20

标签: java mysql database-connection datasource c3p0

我正在使用c3p0连接池进行数据库连接,这是我的DbConnection类,我正在连接数据库,

public class DbConnection {
    private static ComboPooledDataSource dataSource;
    private static Logger logger = Logger.getLogger(DbConnection.class);
    static {
        try {
            dataSource = new ComboPooledDataSource();
            dataSource.setDriverClass("com.mysql.jdbc.Driver");
            dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/tickettracking");
            dataSource.setUser("root");
            dataSource.setPassword("root");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
    }

    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }

    public ComboPooledDataSource getDataSource() {
        return dataSource;
    }
}

DbConnection.getConnection()返回的连接在执行2或3个语句后被挂起。一段时间后,浏览器窗口显示错误消息,

enter image description here

这是我的日志文件在创建dataSource时显示的内容

2015-04-15 10:59:22 INFO MLog:124 - MLog clients using log4j logging.
2015-04-15 10:59:22 INFO C3P0Registry:248 - Initializing c3p0-0.9.5 [built 02-January-2015 13:25:04 -0500; debug? true; trace: 10]
2015-04-15 10:59:22 INFO AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1br4bb8981g1ezhfm6agtx|4f98b5c, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceUseNamedDriverClass -> false, identityToken -> 1br4bb8981g1ezhfm6agtx|4f98b5c, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/tickettracking, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]

我尝试过增加池大小,每个连接的语句数量,在使用后关闭连接但没有解决问题。为什么连接在执行3(最大)语句后没有做出任何响应?我是否以错误的方式创建连接,或者是否有更多内容要添加到dataSource。我在生命中第一次使用c3p0 api。

更新  我在单个浏览器上测试我的Web应用程序,并且在c3p0 API文档中提到了“C3p0连接池仍可以使用默认值”。

0 个答案:

没有答案