Hibernate appears suspended animation after running for a period of time

Hibernate appears suspended animation after running for a period of time


   Recently, I was maintaining a project of Hibernate+spring+spring mvc left by outsourcing. I found that after the project was running for a period of time, I found that the APP request has been in a waiting state until the request timed out, so I debugged and traced it and found that it was when the database was operated. It has not returned. At first I thought it was the database connection timeout, but then I thought about it, the connection timeout should report an exception, but this is no exception, the program will not go down when the SQL statement is executed, and stop, The phenomenon of suspended animation has not returned, so it is concluded that the connection pool of the database is full because the connection is not closed after operating the database. However, after looking at the code, it is found that DAO inherits spring's HibernateDaoSupport, so the closure of the session should be managed by spring. , the code does not need to be closed manually, I was depressed for a while, I decided to look at the code in the DAO carefully, this time I found a very problematic operation, the code directly uses this.getSession() to operate the data and does not close it manually This session, instead of operating the database through this.getHibernateTemplate().getSessionFactory().openSession(), later checked and found that if you use this.getSession(), you need to manually close the session. So, I used this. getSession(), close the session after operating the database, after running for a long time, there is no suspended animation.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564633&siteId=291194637