Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does a Connection time out?

 
Mike London
Ranch Hand
Posts: 1227
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a Connection in a servlet that gets instantiated as per web.xml in a web app.
However, after a day or so, trying to log in (where you need the Connection to verify user name and password in the database), the error in the Tomcat Logs is that "Connection.close() has been called.".
Do Connections time out?
I've added code to check for the connection being closed and have resolved this problem, but I'm still not sure why the connection closed in the first place.
Any ideas or input would be welcome.
Thanks.
- Mike
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They can, but I believe it's database dependent. As far as I'm aware, MySQL times out Connections after 8 hours. There are a few ways to manage this, but the easiest is to use a ConnectionPool that verifies a Connection before it hands it to you, or even better one that keeps the Connections alive by running dummy queries after a few hours of inactivity. I don't know if they still do, but the old (4.5) WebLogic pooling could be configured to do this for you.
MySQL also supports ?autoReconnect=true at the end of the database URL to allow Connections to refresh after they are timed out by the database, but I'm not aware of anything similar in other databases.
Dave
 
Ryan Bailey
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with David.
Why not use Connection pooling? I use it with Tomcat on MySQL and it's very easy to set up. If you are using the same configuration and need help, just let me know. It's better for the container to manage connection state rather than trying to program it in to your webapp.
Just my $.02 worth
Cheers
Ryan
 
Mike London
Ranch Hand
Posts: 1227
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All!!!
Yes, I'm using MySQL and I think David is totally correct. It's about 8 hours when the message "Connection.close() has already been called...".
I would like to set up Connection Pooling, but the documentation for the Connect/J driver seems to be a bit complicated. I'm sure once I "dive in" it would only take a few hours to get working.
Is it your experience that setting up connection pooling is a snap under MySQL 4.0.17 and Connector/J and Tomcat 5?
Thanks in advance for all replies.
-- Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic