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.

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量