简体   繁体   English

如何在jmx中显示EhCache的统计信息

[英]How to show the statistics of EhCache in the jmx

I set up some caches to test the caching for some DTOs. 我设置了一些缓存来测试某些DTO的缓存。 Now I want look at the statistics from the caches in the jconsole . 现在,我想看看jconsole中缓存的统计信息 The problem is that they are not provided . 问题是没有提供它们。

Maybe, the caches don´t work correctly and this is the reason why there no values in the statistics. 也许缓存无法正常工作,这就是为什么统计信息中没有值的原因。 But i don't see any error in the code or when i start the server, so i think they must work properly. 但是我在代码中或启动服务器时没有看到任何错误,因此我认为它们必须正常工作。

My code in the spring.xml: 我在spring.xml中的代码

<!-- ******************** EhCache DTO caching ************************ -->

<ehcache:annotation-driven create-missing-caches="true" cache-manager="dtoCacheManager" />

<bean id="dtoCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
    p:config-location="dtoEhcache.xml" p:shared="true"/>



<!-- ***** register cache with JMX ***** -->

<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true" />
</bean>


<bean id="ehCacheMBeanRegistration" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod" value="net.sf.ehcache.management.ManagementService.registerMBeans"/>
    <property name="arguments">
        <list>
            <ref bean="dtoCacheManager"/>
            <ref bean="mbeanServer"/>
            <value>true</value>
            <value>true</value>
            <value>true</value>
            <value>true</value>
        </list>
    </property>
</bean>

My code in the dtoEhcache.xml: 我在dtoEhcache.xml中的代码

<!-- ***** Config for the Caches ***** -->

<?xml version="1.0" encoding="UTF-8"?>

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
monitoring="autodetect" dynamicConfig="true" updateCheck="false">

<diskStore path="java.io.tmpdir/DtoEhCacheSpring" />

<defaultCache eternal="false" maxElementsInMemory="1000"
    overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
    timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" statistics="true" />

<cache name="brandDataCache" eternal="false" maxElementsInMemory="1000"
    overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
    timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" statistics="true" />

<cache name="cmsSiteCache" eternal="false" maxElementsInMemory="1000"
    overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
    timeToLiveSeconds="1000" memoryStoreEvictionPolicy="LRU" statistics="true" />

<cache name="contentPageCache" eternal="false"
    maxElementsInMemory="1000" overflowToDisk="false" diskPersistent="false"
    timeToIdleSeconds="0" timeToLiveSeconds="1000"
    memoryStoreEvictionPolicy="LRU" statistics="true" />

A example of a Method which should be cached: 应缓存的方法示例:

 @Cacheable(cacheName = "brandDataCache")
public BrandData convert(final BrandModel brandModel, final BrandData prototype) throws ConversionException {
... impl ... }

I find the error. 我发现了错误。 It wasn't a problem with the jmx config. jmx配置不是问题。 It was a problem with the placing of the cacheable annotation. 放置可缓存注释存在问题。 The cache will be only triggert if the method is called from outside the class. 仅当从类外部调用该方法时,才会触发缓存。 I placed it wrongly on a method that is only called inside the class (facepalm). 我错误地将其放在仅在类(facepalm)内部调用的方法上。 I changed the annotation to the other method and now it works. 我将注释更改为其他方法,现在可以使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM