web容器中用jmx监控hibernate sessionFactory
以tomcat为例,加入一个listner监听容器启动:
<listener> <description>ServletContextListener</description> <listener-class>com.my.listener.StartupListener</listener-class> </listener>
Listener中的内容:
@Override public void contextInitialized(ServletContextEvent sce) { SessionFactory sf = HibernateUtil.getSessionFactory(); MBeanServer ms = ManagementFactory.getPlatformMBeanServer(); Hashtable tb = new Hashtable(); tb.put("type", "statistics"); tb.put("sessionFactory", "myHibernateApp"); try { ObjectName on = new ObjectName("hibernate",tb); StatisticsService mBean = new StatisticsService(); mBean.setSessionFactory(sf); mBean.setStatisticsEnabled(true); ms.registerMBean(mBean, on); } catch (Exception ex) { Logger.getLogger(StartupListener.class.getName()).log(Level.SEVERE, null, ex); } }
tomcat启动需要添加一行jvm参数:-Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
用来启动tomcat的jmx服务管理。
启动后通过jconsole访问tomcat的jmx监听端口。
相关推荐
明天就流量监控 2020-06-05
jocleyn 2020-04-29
bktest 2020-02-22
TesterJingel 2020-02-17
itmale 2020-01-18
Cherishyuu 2019-12-22
ChenRuiyz 2019-11-01
TRUELOVE 2015-04-10
流量监控lookman 2011-10-20
willpowerlsc 2013-04-16
UsherOu 2015-11-07
raoping0 2015-10-08
kaizhuQin 2013-06-08
一支菜鸟 2019-06-28
花花流量监控 2019-06-28
Kim 2019-06-28
zwjcyz 2012-05-24
Ryan的砖篮 2012-04-16