Reputation: 899
Connection pooling is normally managed by the application server right? But we can add a context.xml in META-INF folder and configure data source there now.
Is that a good approach? Even in this case even we have the configuration in our application, server will pick up those configurations and manage the pooling right?
I have notices when i don't close the connection it returns different connection objects. And if i close the connection it does return the same connection object GenericObjectPool.numActive shows 1 in this case. But when i dont close connections it also returns the connection objects to the pool right? Because i see GenericObjectPool.numActive keep increase for each request.
My second question is though i don't close the connection still those are returned to the connection pool now? so even after request is fulfilled, why is the server not picking that connection object and instead creating a new one?
Upvotes: 0
Views: 613
Reputation: 692141
If you don't close a connection, it won't return to the pool. A connection must ALWAYS be closed, in a finally block, by the method which got it from the pool.
Your server or pool might have means to detect that a connection has not been closed, but isn't used anymore, and thus return it to the pool, but you can't rely on such a mechanism.
Upvotes: 1