Today's Question:  What are the big Internet events in 2015?        GIVE A SHOUT

Technical Article => Database =>  MySQL

Solve Hibernate "Too many connections" issue in MySQL

  sonic0002      2013-09-04 22:20:49      11,698    2    1

When working with Hibernate and MySQL, sometimes some exceptions will be thrown after sometime. The exception may seem like :

java.sql.SQLException: Data source rejected establishment of connection, message from server: "Too many connections"

This means there are too many active connections on the MySQL, you can use

SHOW STATUS LIKE '%Threads_connected%';

to check the active connections to MySQL. If you want to change the maximum connections allowed to MySQL. You can execute:

set global max_connections = [num];

You may forget to manually call session.close() methods iin your codes. If you have done this in all methods. Then you should not forget to call sessionFactory.close() when you have done all the requests. Most of the time, it's because you forget to call sessionFactory.close(). So please don't forget to call sessionFactory.close().

Also Hibernate's own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is not intended for use in a production system, or even for performance testing. You should use a third party pool for best performance and stability. Just replace the hibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate's internal pool. For example, you might like to use c3p0.

   MYSQL HIBERNATE CLOS   Read(11,698) Comment(2) Version(1)




集成显卡 [Reply]@ 2013-09-05 21:04:56



后来用了 c3p0 解决此问题

qwd [Reply]@ 2014-09-24 00:20:10



Mathematician loses to barman

By sonic0002