java – 如何监视c3p0连接

前端之家收集整理的这篇文章主要介绍了java – 如何监视c3p0连接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在JBoss战争中使用Hibernate,使用c3p0进行连接池,都在我的类路径中的一个hibernate.cfg.xml配置文件中配置
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

我看到server.log生成有关连接池的有趣信息的行:

DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@63f5e4b6 [managed:10,unused:9,excluded:0]

对于我的监控池(我使用nagios),我想提供一个JSP,告诉我们正在使用多少个连接,以及有多少个连接是空的,正如日志文件所说.

如何问c3p0有多少管理和未使用的连接?

解决方法

您可以通过 JMX监视连接池.从文档中:

07001

If JMX libraries and a JMX
MBeanServer are available in your
environment (they are include in JDK
1.5 and above),you can inspect and configure your c3p0 datasources via a
JMX administration tool (such as
jconsole,bundled with jdk 1.5). You
will find that c3p0 registers MBeans
under com.mchange.v2.c3p0,one with
statistics about the library as a
whole (called C3P0Registry),and an
MBean for each PooledDataSource you
deploy. You can view and modify your
DataSource’s configuration properties,
track the activity of Connection,
Statement,and Thread pools,and reset
pools and DataSources via the
PooledDataSource MBean. (You may
wish to view the API docs of
07002 for
documentation of the available
operations.)

顺便说一下,Nagios似乎有JMX插件,你不会被迫使用JSP.

猜你在找的Java相关文章