C3p0 freezes pending. Available with sleep mode.

I have a console application hanging at runtime. 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 stack:

 "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 connecton, and it seems that I do not leak them. And also I use one thread. I have not configured any mysql settings other than memory usage. Mysql works fine from the console. Why can this happen? Is this a c3p0 error?

+6
source share
2 answers

Does this happen immediately or after a while? that is, to do checks initially successfully, but then hang like that? if so, it looks like a connection leak. try setting c3p0 unreturnedConnectionTimeout and debugUnreturnedConnectionStackTraces parameters 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 .

if this happens immediately, if the connections were not completed successfully, the question arises as to whether the pool will succeed in receiving the connections. by default, if it never succeeds, after about 30 seconds your thread should break with an error. (this does not look like you did it, but if, for example, you set getRetryAttempts to zero, c3p0 can hang up Connections endlessly.)

to debug c3p0 issues, it’s useful to capture version and configuration information with which c3p0 flushes logs at the INFO level when the pool is initialized.

Good luck

+13
source

In addition, you do not seem to initialize the checkoutTime parameter for c3p0, which determines the time during which the client should wait for a connection from the connection pool.

see http://www.mchange.com/projects/c3p0/#checkoutTimeout

+3
source

All Articles