Solve Hibernate "Too many connections" issue in MySQL
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.
By clicking the "Mark as important" button, this article will be put to your important article list which you can find in "Amin->Article important list". Later when you want reread this article, it's easier for you to find it by checking the "Article important list".
::Comment Zone (Total 1 comment)
:: Other versions
No other versions available yet.
:: Recent articles
- HeartBleed: OpenBSD now starts to clean up OpenSSL
- HeartBleed: Should C be blamed for the HeartBleed bug?
- HeartBleed: Inside the heart, what happens to a normal WEB user?
- Learning Python as your first programming language
- PHP Apache MySQL Set-up Note
- Hey, you may be happy to know these mottos about programming languages
- Tips for a better first-time hackathon experience
- <=> operator in MySQL
- Why does LinkedIn migrate to NodeJS from Ruby?
- more ►
:: Most read
- Cross Browser HTML5 Drag and Drop
- Sony is to release PlayStation4 in 2015
- GCC is compiled with C++ compiler
- TIOBE : C overtakes Java as the No.1 programming language
- 5 Free Open Source Chat Applications For Developers
- Which programming language should I learn first?
- Disposable Email address
- Why PHP is (so much) better than Ruby?
- Is Ubuntu becoming a big name in enterprise Linux servers?
- Great code is written twice (or more)
- more ►
:: Find us