I'm in the process of adding connection pooling to our java app.
The app can work with different rdbmses, and both as a desktop app and as a headless webservice. The basic implementation works fine in desktop mode (rdbms = derby). When running as a webservice (rdbms = mysql), we see that connection pooling is needed to get good concurrent behaviour.
My initial approach was to use dependency injection to decide between a basic DataSource or a connection pooling DataSource at startup time.
The problem in this scenario is that I don't know when to call connection.close(). My understanding is that when using connection pooling, you should close() after each query so the connection object can be recycled. But the current non-pooling implementation tries to hang on to the Connection object as long as possible.
Is there a solution to this problem? Is there a way to recycle a basic connection object? What happens if I don't call connection.close() with a thread pooled connection object?
Or is it simply a bad design to mix these two connection strategies?