• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MySQL database connection fails after long idle

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a MySQL question.

I would like to keep a MySQL database open for long periods of time without opening and closing it regularly (reason: it runs under Apache Tomcat, and for each request to the servlet, the servlet gets a request number from a MySQL database and table).

However, if left idle for a long period (i.e., no requests to the servlet for a long time), the database connection fails.

One solution is to open and close the database for each request, but I would think that would be expensive.

I'm wondering if a long idle connection failure is a common problem, and I am seeking advice on how best to use MySQL in this way.

David
 
Dave Anderson
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The more I think about this problem I have, the more I think it can be solved by simply opening and closing the database, as I suggested, but with the cavaet that a "block" of request numbers be issued and dispensed.

I have implemented such a solution, so there is no need to respond to this ticket.

David
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I have a comment anyway.

Yes, MySQL will notice after several hours that a connection hasn't been used, and drop its end of the connection. That of course makes it useless for the client, as you observed.

But you're concerned that it would be "expensive" to repeatedly create new connections. That might be the case, but doing an "expensive" operation (what does it take? half a second?) every few hours shouldn't be a concern. I think you are prematurely optimizing here. Just do this: if you try to use the connection, and it's broken, then close the database, open it again, and create a new connection.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic