[Logo]
Forums Register Login
Does a Connection time out?
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
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
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
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 11, 2017 08:10:18.