commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Jason Brzozowski" <jjmb...@gmail.com>
Subject Re: Apache DBCP Question
Date Wed, 06 Aug 2008 19:33:06 GMT
Thanks for replying Simon.  I also tried something else that appears to have
provided some benefit.  I proceeded to create a connection from the pool for
specific uses, one for query type A, one for query type B, and one for
inserts.  Three connections were created and things seem to be behaving,
however, not ideal.

Originally, I intended to leverage the pools to increase the performance of
updates.  So in the case you describe below I can create a pool of "n"
connections.  Assuming a threaded application each thread (assuming these
are for updates in this case) uses a separate connection I need to make sure
the number of threads performing inserts/updates does not exceed the number
of available connections.  If this happens then a connection needs to be
freed up to allow subsequent threads or updates to be processed.

Thanks again,

John

On Wed, Aug 6, 2008 at 5:13 AM, simon.kitching@chello.at <
simon.kitching@chello.at> wrote:

> John Jason Brzozowski schrieb:
>
>>        try {
>>
>>            logger.info("Loading MySQL driver");
>>            Class.forName("com.mysql.jdbc.Driver");
>>            logger.debug("Connecting to " + mDbUrl + " as " + mDbUser +
>> "/(Password not displayed)");
>>            mconn =
>> DriverManager.getConnection("jdbc:apache:commons:dbcp:foo");
>>            if(!mconn.isClosed()) {
>>                logger.trace("Connected to MySQL database");
>>            }
>>            ...
>>                }
>>            }
>>          } catch (Exception e) {
>>              logger.fatal(e);
>>              e.printStackTrace();
>>          }
>>
>> When I print the number of connections active and idle I get the
>> following:
>>
>> TRACE [main] (?:?) - Connection pool idle connections, 0, active
>> connections, 1
>>
>> The number of active connections never increases past one.  I thought the
>> following would cause 10 connections to be created:
>>
>>        gkopc.maxActive = 10;
>>
>> Any comments on what I missing would be greatly appreciated.  To provide
>> additional context I wish to use connection pooling when making large
>> quantities of database updates.  Most examples I see are for SELECTs not
>> INSERTs.
>>
>>
> It's been a long time since I've used DBCP.  But as no-one has answered,
> I'll offer a suggestion.
>
> That maxActive looks like a *maximum* setting.
>
> Try this:
>  Connection[] conns = new Connection[20];
>  for(int i=0; i<8; ++i) {
>   conns[i] = DriverManager.getConnection(....);
>  }
> then dump the output.
>
> I would expect that then you will see 8 active connections reported.
>
> And if you increate the loop to > 10, then it will probably hang, as the
> attempt to fetch the 11th connection will block until someone returns one of
> the existing ones. Which would happen in a threaded app, but won't happen
> here in a single-threaded test.
>
> Regards, Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
===================================
John Jason Brzozowski
===================================

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message