views:

150

answers:

1

I'm writing new DB connection code, and thought I'd try proxool as the connection pool implementer.

Normally, a programmer would ensure that every DriverManager.getConnection(...) is followed by a connection.close().

But when using Proxool, is the close needed? I'm confused because:

a. The proxool documentation here (http://proxool.sourceforge.net/quickStart.html) shows the close() being called, yet,

b. I read someplace that proxool adds shutdown hooks that close all connections when the program exits.

My program's paramount concern is performance (up to 200 DB writes/second), so I'm not sure how Proxool's getConnection()/close() will impact performance.

My questions are:

  1. Is the close() needed, or can I rely on Proxool to close my connections?

  2. If I have to explicitly call the close() myself every time, won't that adversely affect performance?

Thanks in advance.

+3  A: 

Database pools generally subclass / decorate connections so that close() method, if it's invoked by the application, doesn't actually close the connection but instead releases it back into the pool. This is done for performance reasons because establishing new connection each time can be quite costly as well as in order to improve your user / connection ratio.

That said, you DO need to call connection.close(), thus letting the pool know that you're no longer using it and it can be made available to the next thread that requests it.

ChssPly76