Issue Details (XML | Word | Printable)

Key: DBCP-221
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dain Sundstrom
Reporter: Bill Liu
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Dbcp

How to close the connection pool without shutting down the JVM while there are connections being used?

Created: 11/May/07 12:04 AM   Updated: 22/Oct/09 10:43 AM
Return to search
Component/s: None
Affects Version/s: 1.2.2
Fix Version/s: 1.3

Time Tracking:
Not Specified

Resolution Date: 23/Jul/07 10:29 PM


 Description  « Hide
Suppose there are several connections being used now by different servlets. calling the basicDataSource,close() does not have any impact on the connection pool. I expect that after these servlet return the connections the pool should be shut down immediately. I also expect that any more requests to borrow connections from the pool should not be fulfilled. However, my experiment does not seem to support my expectations. Calling basicDataSource.close() seems to be ignored while there are connections being used.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Phil Steitz added a comment - 11/May/07 04:57 AM
Behavior here is determined by the underlying pool. In the case of commons pool's GenericObjectPool, which BasicDataSource uses, the close method only closes idle connections in the pool. The BasicDataSource Javadoc should be improved to make it clear that only idle connections are closed when close is invoked on the BasicDataSource.

Phil Steitz made changes - 11/May/07 04:57 AM
Field Original Value New Value
Fix Version/s 1.3 [ 12311977 ]
Bill Liu added a comment - 11/May/07 04:39 PM
Thanks Phil.

So what is the appropriate way to shut down (forcefully) a connection pool, assuming we have a serious db issue?


Repository Revision Date User Message
ASF #558884 Mon Jul 23 22:28:37 UTC 2007 dain DBCP-221 Changed BasicDataSource.close() to permanently mark the data source as closed. At close all idle connections are destroyed and the method returns. As existing active connections are closed, they are destroyed.
Files Changed
ADD /jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java
MODIFY /jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
MODIFY /jakarta/commons/proper/dbcp/trunk/pom.xml
MODIFY /jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
MODIFY /jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolableConnection.java
MODIFY /jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestAll.java
MODIFY /jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/ManagedConnection.java
MODIFY /jakarta/commons/proper/dbcp/trunk/project.xml

Dain Sundstrom added a comment - 23/Jul/07 10:29 PM
BasicDataSource.close() now permanently marks the data source as closed. No new connections can be obtained from a closed data source. At close all idle connections are destroyed and the method returns. As existing active connections are closed, they are destroyed.

Dain Sundstrom made changes - 23/Jul/07 10:29 PM
Assignee Dain Sundstrom [ dain ]
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Henri Yandell made changes - 25/Mar/08 08:11 AM
Status Resolved [ 5 ] Closed [ 6 ]
Roshan Gunasekara added a comment - 21/Oct/09 09:41 AM
I agree with the change of behaviour of close() so that its permanently closed.

However we relied on the current behaviour as a way of restarting the Connection Pool after changing its properties without a full JVM restart. (e.g. change the Database URL). I agree this is a hack and there is no guarantee it will continue to work.

But I think you might agree, is a useful feature to have. Looking at the source code, I spotted a restart() method which is currently private and not used, which just calls close().

Will it make sense to expose this method and have an overloaded method close(boolean permanent) which controls if its a permanent close or not.

If you agree, I am happy to submit a patch.


Phil Steitz added a comment - 22/Oct/09 10:43 AM
The problem with supporting restart is that you either have to force close the connections that are checked out to clients (not generally a happy scenario) or you no longer have a uniform pool of connections. Deciding how to handle the latter problem from the pool's perspective is probably what stalled the implementation of "restart". If you have ideas about how to implement this without adding too much complexity for the user or dbcp iteslf, we should discuss them on the dev list.