使用JConsole监控带有Hibernate和Tomcat的c3p0。

5
Web App是一个Struts应用程序(没有Spring),使用c3p0和Hibernate,并在Tomcat 6中运行。Hibernate和c3p0 JAR文件都在{WEB_APP} / WEB-INF / lib文件夹中。
在Tomcat中启用了jmx远程: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 当我使用jconsole连接时,在选项卡中看不到c3p0 MBean。
是否需要在Tomcat或Web应用程序中进行任何配置?
谢谢!

1
你解决了这个问题吗?我们这里也遇到了同样的问题。 - user831354
1个回答

2

如果您没有使用Spring或JBoss,那么在进行Hibernate的JMX监控时需要更加手动操作。

您需要执行以下步骤:

  • In your Hibernate Configuration add:

    <property name="hibernate.generate_statistics">true</property>
    
  • Then in a startup segment of your app you need to register the MBeans with the MBean server:

    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName("org.hibernate:type=statistics"); StatisticsService mBean = new StatisticsService(); mBean.setStatisticsEnabled(true); mBean.setSessionFactory(sessionFactory); mbeanServer.registerMBean(mBean, objectName);


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接