Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best choice for database connection pooling library? (c3p0 problem)

I have heavy loaded java application using hirbernate. And I used to use as connection pool DBCP, but it had problems with connections lossing. Than I switched to c3p0. But now it sometimes bloks thread and I dont know why. Like here:

"1343694829@qtp-515693101-1941" prio=10 tid=0x00007fa6b0940000 nid=0x4e12 runnable [0x00007fa6f8f1c000]
   java.lang.Thread.State: RUNNABLE
    at com.mchange.v2.resourcepool.BasicResourcePool.doCheckinManaged(BasicResourcePool.java:1258)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkinResource(BasicResourcePool.java:647)
    - locked <0x00007fa7286d9728> (a com.mchange.v2.resourcepool.BasicResourcePool)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$ConnectionEventListenerImpl.doCheckinResource(C3P0PooledConnectionPool.java:636)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$ConnectionEventListenerImpl.connectionClosed(C3P0PooledConnectionPool.java:630)
    at com.mchange.v2.c3p0.util.ConnectionEventSupport.fireConnectionClosed(ConnectionEventSupport.java:55)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.fireConnectionClosed(NewPooledConnection.java:510)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.markClosedProxyConnection(NewPooledConnection.java:381)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.close(NewProxyConnection.java:1246)
    - locked <0x00007fa794ccf020> (a com.mchange.v2.c3p0.impl.NewProxyConnection)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.closeConnection(LocalDataSourceConnectionProvider.java:96)
    at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
    at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:408)
    at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:347)
    at org.hibernate.impl.SessionImpl.close(SessionImpl.java:325)
    at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession(SessionFactoryUtils.java:791)
    at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSessionOrRegisterDeferredClose(SessionFactoryUtils.java:777)
    at org.springframework.orm.hibernate3.SessionFactoryUtils.releaseSession(SessionFactoryUtils.java:755)

' My stacktrace dump showed that this thread blocked all my other threads, with lock <0x00007fa7286d9728>, so in a while server was completly blocked. I am not sure how long does this thread run, if one thread was blocking all other threads for long time, or if just time consumed by this thread was extremly long, but result was, that my system was completly blocked and extremly slowed. I googled a lot, but I don't know how to solve this problem. I need pool to close connection and finish tread as soon as possible. Should I use some other connection pool? For me it is absolutly necessary that this pool library is 100% save, no deadlocks, lifelocks, starvations, even that it is little bit slower than other libraries.

thanks for any help

like image 750
Libor Havlicek Avatar asked Nov 22 '10 11:11

Libor Havlicek


People also ask

Which library is used for database connection pooling?

Many Java Application Frameworks include their own connection pooling APIs. But the principles used to configure all frameworks are generally the same. In this article, you'll learn how to create a database connection pool using the Java Database Connectivity (JDBC) API and the Apache DBCP pooling library.

Which is the best connection pooling in Java?

There are multiple JDBC frameworks for connection pooling the most popular choices being Tomcat JDBC and HikariCP. Whatever framework you choose it's important to configure the properties correctly, (a big plus of HikariCP is that it offers good defaults for optional configs).

What is a connection pool how it provides a better performance?

In software engineering, a connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools are used to enhance the performance of executing commands on a database.


2 Answers

You may wish to have a look at BoneCP - http://jolbox.com.

Much better performance than C3P0/DBCP and no reports of any deadlocks so far.

like image 135
wwadge Avatar answered Sep 20 '22 15:09

wwadge


1)What do you mean when say about connection losing in DBCP? Do you use MySQL? I know problem with connection losing with working with MySQL if no activity were during some time. Is it your case?

2)Using Hibernate in high-loaded app isn't very good choice. Hibernate is too bulk and slow especially on complex data and relations (for example it need transaction on every session even we just want to retrieve data)

3)May be reason is too much needed threads and not enough threads in the pool?

I participated in high-loaded project. We use Hibernate for soft data (plenty of requests consisted of several records that had not very complex mapping) and self-written wrapper over JDBC for heavy data (not very much requests of thousands records via SP with hard manual mapping). And we didn't have any problems with DBCP except losing connection to MySQL databases after long inactivity time.

like image 20
Donz Avatar answered Sep 19 '22 15:09

Donz