GeeCON Prague 2014*
The moose likes Tomcat and the fly likes relinquishing database connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "relinquishing database connections" Watch "relinquishing database connections" New topic
Author

relinquishing database connections

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
We have a web app whose connection pooling code is modeled on basic example stuff on the web (classes like ConnectionPool, PooledConnection, etc), and my understanding is that when we restart Tomcat, all the ODBC connections will be reset on the database side. Now, we know that our particular ODBC driver has a problem which results in them not being reset sometimes, but generally it does release them.

Now, I'm wondering how the driver even knows to release them to begin with (when it's working right, I mean). Does Tomcat specifically tell the driver a special command to release all the connections or something like that?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Since the question concerns the inner workings of Tomcat, I'm moving this along to the Tomcat forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Stephen,

Are you using DBCP, the built-in db connection pooling that comes with Tomcat, or your own customer pool?

If custom, then it's up to you to close down connections when your pool is on it's way out. Is this why you're asking about how Tomcat does it?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I didn't write the original code, but the connection pooling classes look like a lot of the example stuff on the web, and I think it's possible that it may even be an early version of the Apache group's connection pooling code (but slightly tweaked for our app).

I see that our connection object implements Connection, and since we have a method called close() that tries to get the db driver to close the corresponding connection on the db side, I'm assuming that when Tomcat is shutting down, then the Connection interface requires Tomcat to call the close method on each of those objects...

Does that sound right? We're pretty soon our connection pooling code isn't buggy, especially since I've been told that we once switched out the Apache group's package and there was no difference, but I'm just trying to eliminate possibilities...

(So to answer one of your questions, I don't think we're using Tomcat's built-in connection pooling...also, right now we're using Tomcat 4.27, I think).
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

...I'm assuming that when Tomcat is shutting down, then the Connection interface requires Tomcat to call the close method on each of those objects.

I think this is an invalid assumption. There's nothing in the Connection API itself that indicates to me that when an Connection object is being gc'd, that the JVM should first call .close().

SharedPoolDataSource from DBCP has a .close() method on it. I bet if you searched through tomcat source, you'd see where Tomcat calls the .close() method for all the container-managed DataSources.

If you're not doing the same thing for your own Pool... then it's possible these connections are not being shut properly.
 
GeeCON Prague 2014
 
subject: relinquishing database connections