Servlet hibernation timeout issue

I have a Tomcat servlet that enables hibernation. It is working fine. When the servlet starts, I initialize sleep mode and create a factory session. Then I use this factory session to create sessions when doing various database transactions. So far, so good. My problem arises after a long period of inactivity of the servlet (say when users go home at night and then try to log in the next morning). Suddenly I can’t communicate with the data. In the magazines I see

org.hibernate.exception.JDBCConectionException: The request failed.

If I stop and restart Tomcat by reinitializing my servlet and rebuilding the factory session, everything works fine. Does it almost look like a factory timeout session itself?

Any ideas?

Thank,

Elliot

+3
source share
1 answer

If I stop and restart Tomcat by reinitializing my servlet and rebuilding the factory session, everything works fine. Does it almost look like a factory timeout session itself?

This is not a factory session, but the connections used by the factory session (for example, MySQL is well known for the timeout after 8 hours of inactivity by default). Or:

  • use a connection pool capable of checking borrowed connections and updating ~ or ~
  • increase database idle timeout

OK. , c3P0. hibernate.cfg.xml, " " ?

C3P0 . : idleConnectionTestPeriod:

. . idleConnectionTestPeriod testConnectionsOnCheckIn. , , .

, , . , c3p0 . idleConnectionTestPeriod, , .

C3P0 Hibernate, ( ).

+3

Source: https://habr.com/ru/post/1770647/


All Articles