java c3p0 挂在 awaitAvailable 和休眠状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14105932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
c3p0 hangs in awaitAvailable with hibernate
提问by Stepan Yakovenko
I have console application that hangs during execution. Here is my configuration:
我有在执行过程中挂起的控制台应用程序。这是我的配置:
cfg.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db?user=db&password=db");
cfg.setProperty("hibernate.connection.username", "db");
cfg.setProperty("hibernate.connection.password", "db");
cfg.setProperty("hibernate.connection.pool_size", "5");
cfg.setProperty("hibernate.connection.autocommit", "false");
cfg.setProperty("hibernate.c3p0.min_size", "5");
cfg.setProperty("hibernate.c3p0.max_size", "20");
cfg.setProperty("hibernate.c3p0.timeout", "300");
cfg.setProperty("hibernate.c3p0.max_statements", "50");
cfg.setProperty("hibernate.c3p0.idle_test_period", "3000");
Here is my stacktrace:
这是我的堆栈跟踪:
"main" prio=10 tid=0x000000000168f800 nid=0x1c37 in Object.wait() [0x00007fa60d0ad000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007400f4c68> (a com.mchange.v2.resourcepool.BasicResourcePool)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1315)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
- locked <0x00000007400f4c68> (a com.mchange.v2.resourcepool.BasicResourcePool)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:84)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:281)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1392)
at org.kriyak.parser.IndexArchiveRapid.indexFile(IndexArchiveRapid.java:70)
at org.kriyak.parser.IndexArchiveRapid.main(IndexArchiveRapid.java:53)
I open only one conencton and it doesn't seem that I leak them. And also I use one thread. I haven't adjusted any mysql settings except memory usage. Mysql works fine from console. Why can this happen? Is this c3p0 error?
我只打开一个连接,似乎我没有泄漏它们。而且我使用一个线程。除了内存使用,我没有调整任何 mysql 设置。Mysql 从控制台运行良好。为什么会发生这种情况?这是 c3p0 错误吗?
回答by Steve Waldman
does this happen immediately, or after a while? that is, do checkouts initially succeed, but then hang like this? if so, it looks like a Connection leak. please try setting c3p0 params unreturnedConnectionTimeout and debugUnreturnedConnectionStackTraces to see if there is a leak. See http://www.mchange.com/projects/c3p0/#configuring_to_debug_and_workaround_broken_clients, http://www.mchange.com/projects/c3p0/#unreturnedConnectionTimeout, http://www.mchange.com/projects/c3p0/#debugUnreturnedConnectionStackTraces.
这是立即发生的,还是一段时间后发生的?也就是说,结帐最初是否成功,然后像这样挂起?如果是这样,它看起来像连接泄漏。请尝试设置 c3p0 参数 unreturnedConnectionTimeout 和 debugUnreturnedConnectionStackTraces 以查看是否存在泄漏。参见 http://www.mchange.com/projects/c3p0/#configuring_to_debug_and_workaround_broken_clients、http://www.mchange.com/projects/c3p0/#unreturnedConnectionTimeout、http://www.mchange.com/projects/c3p0/# debugUnreturnedConnectionStackTraces。
if this happens immediately, if no Connections are successfully checked out, the question is whether the pool ever succeeds at acquiring Connections. by default, if it never does succeed, after about 30 seconds your thread should break with a failure. (it doesn't look like you've done this, but if for example you'd set acquireRetryAttempts to zero, c3p0 might hang indefinitely waiting for Connections.)
如果立即发生这种情况,如果没有成功签出连接,则问题是池是否曾经成功获取过连接。默认情况下,如果它永远不会成功,大约 30 秒后,您的线程应该会因失败而中断。(看起来您没有这样做,但是例如,如果您将acquireRetryAttempts 设置为零,c3p0 可能会无限期地挂起以等待连接。)
to debug c3p0 issues, it's helpful to capture the version and config information that c3p0 dumps to logs at INFO level on pool initialization.
要调试 c3p0 问题,在池初始化时捕获 c3p0 转储到 INFO 级别日志的版本和配置信息会很有帮助。
good luck!
祝你好运!
回答by Don Bosco
Also, you haven't seem to initialize the checkoutTime parameter for c3p0, which specifies the amount of time a client should wait for acquiring a connection from the connection pool.
此外,您似乎还没有为 c3p0 初始化 checkoutTime 参数,该参数指定客户端应等待从连接池获取连接的时间。