Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

relinquishing database connections

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64610
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the question concerns the inner workings of Tomcat, I'm moving this along to the Tomcat forum.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic