You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Justin Cranford (JIRA)" <ji...@apache.org> on 2015/07/17 07:14:04 UTC

[jira] [Created] (POOL-299) testOnBorrow overrides testOnCreate=false, add testOnReuse to compliment testOnCreate

Justin Cranford created POOL-299:
------------------------------------

             Summary: testOnBorrow overrides testOnCreate=false, add testOnReuse to compliment testOnCreate
                 Key: POOL-299
                 URL: https://issues.apache.org/jira/browse/POOL-299
             Project: Commons Pool
          Issue Type: Bug
    Affects Versions: 2.4
         Environment: DBCP 2.1.0 with Commons Pool 2.4.0
            Reporter: Justin Cranford
            Priority: Minor


I am using Commons DBCP 2.1 with Commons Pool 2.4. When borrowing a connection from DBCP, the underlying pool either reuses a connection or creates a new connection. Validation of that connection seems to be triggered in borrowObject() of GenericKeyedObjectPool or GenericObjectPool based on two settings passed from DBCP 2.1.

        if (p != null && (getTestOnBorrow() || create && getTestOnCreate())) {

I would like to only validate reused connections, not new connections. Validating a new connection is redundant since successful creation implies it is valid. Commons Pools 2 does not allowing me to only validate reused connections, though. If I set testOnBorrow=true then Commons Pool 2 validates new or reused connections, and testOnCreate is effectively overridden. If I set testOnBorrow=false, then my only option to set testOnCreate=true which is also not what I need.

I would like to offer a possible solution. If Commons Pool 2 were to add a new setting called testOnReuse, it would compliment testOnCreate like so:

>        if (p != null && ((getTestOnBorrow()) || (!create && getTestOnReuse()) || (create && getTestOnCreate()))) {

This solutions allows testOnBorrow to be backwards compatible. It validates new or reused objects, and it overrides testOnCreate (and testOnReuse). However, now I have the option to only validate reused connections, and not new connections.

- testOnBorrow=false
- testOnCreate=false
- testOnReuse=true

Adding testOnReuse would be ideal. It would have the same default value as testOnCreate. If it could be added to Commons Pool 2, then it can be added to Commons DBCP 2 later, or any other project depending on Commons Pool 2.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)