commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: [dbcp] inconsistently set autocommit
Date Thu, 17 Sep 2015 18:42:25 GMT
On 9/16/15 10:35 AM, Pruitt, Byron S wrote:
> My usual process for learning something is a quick prototype.  For setting up a driver
pool with autocommit = false, I implemented the little quickie prototype below.
>
> Properties dbProp = new Properties();
> dbProp.put("user", "aUser");
> dbProp.put("password", "aPw");
> dbProp.put("loginTimeout", "35");
> dbProp.put("binaryBatchInsert", "true");
> dbProp.put("autocommit", false);
> DataSource dataSource = setupDataSource("myConnectURI", dbProp);  //this the standard
example on the website
>
> Connection conn = dataSource.getConnection();
> System.out.println("autocommit: " + conn.getAutoCommit());   //this prints out false
>
> Next.
> I moved the above code verbatim to my actual server code.
> The first connection I get from the pool has autocommit == false.  I return this connection
back to the pool.
> But the second time I get a connection from the pool it has autocommit == true.
>
> I have no idea why autocommit is set to a different state for the second connection?
 I can do a test and then set to autocommit = false, but I would like to understand the inconsistency.

Great question.  By default, DBCP's PoolableConnectFactory sets
autocommit to true when it returns a connection to the pool.  See
DBCP-97 for the rationale for this default behavior.  This behavior
can be modified by setting the enableAutoCommitOnReturn of
BasicDataSource or PoolableConnectionFactory to false.  You can also
use the defaultXxx properties of BDS or PCF to set default
properties for connections supplied by the pool.  These properties
ensure that connections will be restored to a consistent state when
the are checked out from the pool, even if client code has mutated
them while the connection has been checked out.

Phil
>
> Thanks.
>
> Steve Pruitt
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message