1

As a standard procedure, MySql connection is lost after stated number of hours (default:8) of inactivity. To reconnect to the mysql server after identifying such connection lost I simply do connection = DriverManager.getConnection(url, user, password);

I am not using connection pool and as this trick has not been mentioned in previous connection lost related posts, that makes me wonder if my code will generate any side-effects later? (I say so because testing this code after above instance, I found the sessionlistner is not called after session.invalidate() call.)

mrig
  • 364
  • 1
  • 4
  • 19

2 Answers2

1

Depending on how you handle connection object(s), it can create small client-side memory leak for connection object that was lost. But probably this effect will be so small that you will never see any problems from it.

To minimize this risk, you can do something as simple as SELECT 1 every few minutes from your connection during idle time, such that your connection is still considered active (unless your client dies off completely).

mvp
  • 94,368
  • 12
  • 106
  • 137
1

You'll loose temporary tables and session settings if your connection drops. It sounds like a connection pool would be useful in your situation.

Joshua Martell
  • 7,035
  • 2
  • 28
  • 37
  • Yeah, I think I am experiencing that. Though I am getting MySql connection back, tomcat no more has connection information.I don't expect to face any heavy traffic on the website so trying with a scheduler, to throw timely queries on the DB, to keep the connection alive [link for that](http://stackoverflow.com/questions/4691132/how-to-keep-the-servlet-continously-running/4691650#4691650). Connection pooling will be my last resort if this doesn't works. – mrig Nov 18 '12 at 09:50