开发者

Can I access the c3P0 connection pool properties programmatically?

开发者 https://www.devze.com 2022-12-14 03:52 出处:网络
I am worried that the properties I have set for my C3P0 connection pool are not being used correctly.

I am worried that the properties I have set for my C3P0 connection pool are not being used correctly.

Is there a way I can access the values that are set while the application is running and print them out:

Println("Minimum connections"+connectionNumers.minimum);开发者_如何转开发

Thanks


You can use log4j to output debug information like so:

log4j.logger.com.mchange=DEBUG, STDOUT

### direct log messages to stdout ###
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.Target=System.out
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%t %d{dd/MMM/yyyy:H:mm:ssZ} %5p %c{1}:%L - %m%n

If you put the above in a file called log4j.properties and put that file in your classpath you should get tons of debug output from c3p0.

Example output:

main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:289 - com.mchange.v2.resourcepool.BasicResourcePool@16c06dd config: [start -> 0; min -> 0; max -> 5; inc -> 1; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 300000; mox_resource_age -> 0; max_idle_time -> 100000; excess_max_idle_time -> 0; destroy_unreturned_resc_time -> 0; expiration_enforcement_delay -> 25000; break_on_acquisition_failure -> false; debug_store_checkout_exceptions -> false]
main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:538 - acquire test -- pool size: 0; target_pool_size: 0; desired target? 1
main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:404 - incremented pending_acquires: 1
main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:1291 - awaitAvailable(): [unknown]

log4j


The API does allow you to access these properties programmatically.

Given that you have your ComboPooledDataSource instance:

static final ComboPooledDataSource dataSource = new ComboPooledDataSource();

You can access these properties at runtime, for example:

int minPoolSize = dataSource.getMinPoolSize();

Plus some other helpful info, for example:

int numBusyConnections = dataSource.getNumBusyConnections();
Throwable lastTestError = dataSource.getLastConnectionTestFailureDefaultUser();

source: http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html


you want to see the runtime info or want change the property value? I don not you could change the property value in runtime because these config values are stored in ram.

0

精彩评论

暂无评论...
验证码 换一张
取 消