I have a web application running on tomcat server. The default wait_timeout for MySQL is 28800s i.e 8 hours. So, if there is no interaction with the server in 8 hrs, my application stops working and I have to reload it to make it work. Is there a solution for this?
P.S. I'm using hibernate's getCurrentSession instead of OpenSession.
The usual approach to handling connections would be to use a connection pool. Its connections would probably be cycled (or closed entirely) a lot sooner than 8 hours anyway. So I'm not sure how you figure that the wait_timeout value is relevant.
posted 3 years ago
Here's what I did. I changed the wait_timeout from its default value to 300 and I ran the test and noticed that the application was not responding after 5 min. Also, I'm using C3P0 for connection pooling. But it didn't solve the problem.
There should be a connection pool option that allows you to tell the pool to discard expired connections and create new ones. It's usually paired with a "liveness test", which is a simple SQL query that's invoked on the Connection before assigning it to the webapp. The details vary somewhat depending on what DBMS you use.
When that mechanism is set up, any time the app requests a Connection, the pool pulls the next available one, does the "liveness test", and if the test succeeds, passes the Connection on to the requester. If the Connection is dead, it's discarded from the pool (destroyed) and a new Connection is retrieved, repeat as needed. If the pool runs empty (or maybe below a minimum threshold), then the pool will create new Connections and add them to the pool.
When it comes to destroying a civilization, gas chambers cannot hold a candle to echo chambers.
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library