Hello all. I'm new to the forum and excited to be here.
I have a project written in struts with jsp pages and servlets. I access a mysql database that is on the same server as the code which is running on Tomcat 5.0. I am using a datasource for the mysql database in the code. I have this strange issue. If no one logs into the website for a awhile, when you try to login, the site just hangs and it doesn't make the connection to the database. However if you then press the login button again, which will re-create the datasource connection, it works perfectly and connects, logs in, etc... Then any attempts to login to my application will work fine for a certain period of time (seems to be at leaast 30 minutes, might be quite a lot longer), even in a brand new browser session.
So it seems like after a certain period of time the datasource dies in some way, but then once I "wake it up", after the first failure, it will work again.
Anyone have any ideas?
I can't access my server log till Tuesday to see if there are any hints, but I wanted to get this question out there to see if it sounds familiar. Thanks for any help
By default, a MySQL DB terminate a connection after it's been idle long enough. I'd guess that you're not testing connections when the pool hands them out (most poolers can be configured to do this for you, and not dealing with the broken connection appropriately (or perhaps mysql is not responding to activity on that connection and your DB request hangs).
While you might be able to get MySQL to change the way it behaves, you really need to code for intermittent errors anyway. Stuff happens. Once in a while databases get restarted, etc. etc.
Joined: Feb 19, 2006
I was thinking of something like that.
So do you recommend when I first create the connection in my code (when the user clicks the login button) that I check the connection and if it is closed I just try to create a connection again - which ususally would work the second time?