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
|