Ehcache提供了基于JMX的监控支持,支持对以下几类信息的监控。

  • CacheManager
  • Cache
  • CacheConfiguration
  • CacheStatistics

按照JMX的规范,为了支持对这几类信息的监控支持,Ehcache分别为它们建立了对应的MBean接口,这些接口都定义在net.sf.ehcache.management包中,分别是CacheManagerMBean、CacheMBean、CacheConfigurationMBean和CacheStatisticsMBean。按照JMX的规范,JMX监控页面只能查看MBean中定义的属性(get方法)和执行MBean接口中定义的操作(方法)。比方说CacheManagerMBean的定义如下,它能看到的属性就是status、name、cacheNames、caches、transactionCommittedCount、transactionRolledBackCount和transactionTimedOutCount。能进行的操作是shutdown()和clearAll()。

public interface CacheManagerMBean {

    /**
* Gets the status attribute of the Ehcache
*
* @return The status value, as a String from the Status enum class
*/
String getStatus(); /**
* Gets the name of the cache manager
*
* @return The name of the CacheManager
*/
String getName(); /**
* Shuts down the CacheManager.
* <p/>
* If the shutdown occurs on the singleton, then the singleton is removed, so that if a singleton access method
* is called, a new singleton will be created.
*/
void shutdown(); /**
* Clears the contents of all caches in the CacheManager, but without
* removing any caches.
* <p/>
* This method is not synchronized. It only guarantees to clear those elements in a cache
* at the time that the {@link net.sf.ehcache.Ehcache#removeAll()} mehod on each cache is called.
*/
void clearAll(); /**
* Returns a JMX Cache bean
*
*/
Cache getCache(String name); /**
* Gets the cache names managed by the CacheManager
*/
String[] getCacheNames() throws IllegalStateException; /**
* Gets a list of caches in this CacheManager
* @return a list of JMX Cache objects
*/
List getCaches(); /**
* Get the committed transactions count
* @return the committed transactions count
*/
long getTransactionCommittedCount(); /**
* Get the rolled back transactions count
* @return the rolled back transactions count
*/
long getTransactionRolledBackCount(); /**
* Get the timed out transactions count. Note that only transactions which failed to
* commit due to a timeout are taken into account
* @return the timed out transactions count
*/
long getTransactionTimedOutCount(); }

注册这些MBean,Ehcache提供了一个工具类,ManagementService,可以通过它的registerMBeans方法进行注册,该方法定义如下,后面对应的4个boolean类型的参数,表示是否需要注册对应的MBean,依次表示CacheManager、Cache、CacheConfiguration和CacheStatistics。该工具方法最终会生成一个ManagementService实例,ManagementService实现了CacheManagerEventListener接口,所以它能感知到Cache的变化。

public static void registerMBeans(
net.sf.ehcache.CacheManager cacheManager,
MBeanServer mBeanServer,
boolean registerCacheManager,
boolean registerCaches,
boolean registerCacheConfigurations,
boolean registerCacheStatistics) throws CacheException {
//...
}

以下是一个注册Ehcache对应的MBean的示例代码:

CacheManager cacheManager = new CacheManager();
String cacheName = "test";
Ehcache cache = cacheManager.addCacheIfAbsent(cacheName);
cache.put(new Element("key is a object", "value is a object")); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);

注册之后我们就可以通过jconsole的JMX界面看到对应的MBean的信息了。

Ehcache相关的MBean的objectName的命名规范如下:

  • CacheManager - “net.sf.ehcache:type=CacheManager,name=<CacheManager>”
  • Cache - “net.sf.ehcache:type=Cache,CacheManager=<cacheManagerName>,name=<cacheName>”
  • CacheConfiguration - “net.sf.ehcache:type=CacheConfiguration,CacheManager=<cacheManagerName>,name=<cacheName>”
  • CacheStatistics - “net.sf.ehcache:type=CacheStatistics,CacheManager=<cacheManagerName>,name=<cacheName>”

参考文档 http://www.ehcache.org/documentation/2.7/operations/jmx.html

(本文是基于Ehcache2.10.4所写,由Elim写于2017年10月8日)

Ehcache开启JMX支持的更多相关文章

  1. Tomcat7开启CGI支持的方法

    tomcat默认没有开启cgi支持,因此有了tomat开启cgi的探索.因为原本对tomcat没多了解,所以中间或多或少走了点弯路.还好最终配置成功了,现在jy也用上这个方法了.    该方法在apa ...

  2. Tomcat开启JMX监控 visualvm

    Tomcat开启JMX监控 https://blog.csdn.net/dongdong2980/article/details/78476393

  3. Activemq开启JMX及问题排查

    0.服务端开启JMX服务 一.修改${ ActiveMQ_HOME} /conf/activemq.xml文件 在<broker>标签中添加如下属性:useJMX="true&q ...

  4. Java SpringBoot注解方式开启异步支持

    package task.demo.controller; import org.springframework.beans.factory.annotation.Autowired; import ...

  5. Mina的JMX支持

    以下是一个增加了JMX支持的Mina Echo Server. package org.apache.mina.echoServer; import java.lang.management.Mana ...

  6. datax开启hana支持以及dolphinscheduler开启datax任务

    datax开启hana支持以及dolphinscheduler开启datax任务 前面(@,@) 前段时间因为要做异构数据导入导出,所以搜了下,发现这类工具收费的居多,使用起来未必趁手~ 于是我找了下 ...

  7. Spring Boot中使用EhCache实现缓存支持

     SpringBoot提供数据缓存功能的支持,提供了一系列的自动化配置,使我们可以非常方便的使用缓存.,相信非常多人已经用过cache了.因为数据库的IO瓶颈.一般情况下我们都会引入非常多的缓存策略, ...

  8. 开启JMX功能,使JVisvualVM能够连接JVM

    -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.manageme ...

  9. Nginx 开启PATHINFO支持ThinkPHP框架实例

    ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可.在Apache下只需要开启mod_rew ...

随机推荐

  1. TOMCAT上传下载文件

    实现下载 修改server.xml修改web.xml   实现上传 实现客户端的上传post请求代码实现 实现服务端的处理   小结         实现下载 实现下载需要  - 修改Tomcat中的 ...

  2. Selenium常用API的使用java语言之15-警告框处理

    在 WebDriver中处理JavaScript所生成的alert.confirm以及prompt十分简单,具体做法是使用switch_to_alert()方法定位到alert/confirm/pro ...

  3. 使用注解方式实现 AOP和IoC

    使用注解方式实现AOP和IoC IOC和DI的注解 IOC: @Component:实现Bean组件的定义 @Repository:用于标注DAO类,功能与@Component作用相当 @Servic ...

  4. PHP 函数运行的内存

    函数在运行期间占用的内存,在运行结束后会被回收.但是还有问题不明白,函数内部的echo在函数执行结束后还占用内存吗??? //PHP 函数执行完内存就会被收回 function test() { ec ...

  5. 51nod 1488 帕斯卡小三角 斜率优化

    思路:斜率优化 提交:\(2\)次 错因:二分写挂 题解: 首先观察可知, 对于点\(f(X,Y)\),一定是由某个点\((1,p)\),先向下走,再向右下走. 并且有个显然的性质,若从\((1,p) ...

  6. IntelliJ IDEA——数据库集成工具(Database)的使用

    https://www.cnblogs.com/huiyi0521/p/10125537.html idea集成了一个数据库管理工具,可以可视化管理很多种类的数据库,意外的十分方便又好用.这里以ora ...

  7. CF809E 【Surprise me!】

    我们要求的柿子是张这样子的: \[\frac{1}{n * (n - 1)} * \sum_{i = 1}^n\sum_{j = 1}^{n}\phi(a_i*a_j)*dis(i, j)\] 其中\ ...

  8. python ros 警报上报

    #!/usr/bin/env python2. # -*- coding: utf- -*- import rospy import time from common_msgs.msg import ...

  9. [WEB安全]XXE漏洞总结

    目录 0x00 XML基础 0x01 XML文档结构 0x02 DTD 0x03 实体 0x04 XXE漏洞 0x05 总结一些payload 0x06 XXE漏洞修复与防御 0x07 参考链接 0x ...

  10. avalon.js中使用owl-carousel轮播图

      <?php if($banners){?> <div class="ms-controller" ms-controller="bannerShow ...