我可以通过编程方式访问 c3P0 连接池属性吗?

发布于 2024-08-14 21:59:28 字数 148 浏览 5 评论 0原文

我担心我为 C3P0 连接池设置的属性没有被正确使用。

有没有办法可以访问应用程序运行时设置的值并将其打印出来:

Println("Minimum Connections"+connectionNumers.minimum);

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不如归去 2024-08-21 21:59:28

您可以使用 log4j 来输出调试信息,如下所示:

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

如果将上述内容放入名为 log4j.properties 的文件中,并将该文件放入类路径中,您应该从 c3p0 获得大量调试输出。

示例输出:

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

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

夜雨飘雪 2024-08-21 21:59:28

API 允许您以编程方式访问这些属性。

假设您有 ComboPooledDataSource 实例:

static final ComboPooledDataSource dataSource = new ComboPooledDataSource();

您可以在运行时访问这些属性,例如:

int minPoolSize = dataSource.getMinPoolSize();

加上一些其他有用的信息,例如:

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

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

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

樱娆 2024-08-21 21:59:28

您想查看运行时信息或想要更改属性值吗?我不认为你可以在运行时更改属性值,因为这些配置值存储在内存中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文