Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor c3p0 (with hibernate and Tomcat) with JConsole

The Web App is a Struts application (no spring) using c3p0 with Hibernate and it's in Tomcat 6. Both Hibernate and c3p0 jars are in the {WEB_APP}/WEB-INF/lib folder.

In Tomcat the jmx remote is enabled: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

When I use jconsole connecting to it, I do not see the c3p0 MBean in the tab.

Is there any configuration I need to do in Tomcat or the web app?

Thanks!

like image 866
Helen S. Avatar asked Nov 05 '22 20:11

Helen S.


1 Answers

When you are not using Spring or JBoss then things are a little more hands on when it comes to JMX monitoring of Hibernate.

You need to do the following:

  • 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);

like image 87
Matt Aldridge Avatar answered Nov 09 '22 12:11

Matt Aldridge