使用 JConsole 监控 c3p0(使用 hibernate 和 Tomcat)

发布于 2024-11-15 16:34:36 字数 422 浏览 6 评论 0原文

Web 应用程序是一个 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 应用程序中进行任何配置吗?

谢谢!

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!

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

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

发布评论

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

评论(1

听风念你 2024-11-22 16:34:36

当您不使用 Spring 或 JBoss 时,当涉及到 Hibernate 的 JMX 监控时,需要更多的动手操作。

您需要执行以下操作:

  • 在 Hibernate 配置中添加:

    true;
    
  • 然后在应用程序的启动部分中,您需要向 MBean 服务器注册 MBean:

    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("org.hibernate:type=statistics");
    统计服务 mBean = 新的统计服务();
    mBean.setStatisticsEnabled(true);
    mBean.setSessionFactory(sessionFactory);
    mbeanServer.registerMBean(mBean, objectName);

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

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