Here's how you can do it :
<ehcache:config configLocation="classpath:config/ehcache.xml" failQuietly="true" />
<ehcache:annotations>
<ehcache:caching id="yourCacheModel" cacheName="yourCache"/>
</ehcache:annotations>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean class="net.sf.ehcache.management.ManagementService" init-method="init">
<constructor-arg ref="cacheManager" />
<constructor-arg ref="mbeanServer" />
<constructor-arg value="true" />
<constructor-arg value="true" />
<constructor-arg value="true" />
<constructor-arg value="true" />
</bean>
After doing this, you will have access to your caches configuration and operations such as cache flushing. You will also have access to useful statistics like cache hits, cache misses, object count and some more. These statistics will give you critical information on how to configure your caches for an optimal use.
Resources :
- JMX Management and Monitoring from the ehcache official documentation.
Julien,
ReplyDeleteWhat does "ref='cacheManager'" referring to?
Simeon
The use of the annotation ehcache:config will create a bean named cacheManager.
ReplyDeleteJulien, what schemaLocations are you using. I'm getting:
ReplyDeleteAttribute 'configLocation' is not allowed to appear in element 'ehcache:config'.
Hi,
ReplyDeleteI'm using :
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
and
schemaLocation="http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"
Hello,
ReplyDeleteWe have packaged EhCache JMX registration in a compact Spring XML namespace based configuration declaration :
<management:eh-cache-management-service
mbean-server="mbeanServer"
cache-manager="cacheManager" />
We also published an Hyperic HQ plugin to monitor EhCache caches (hit/miss ratio, size, etc).
Details are here.
This util is part of larger Open Source JMX/Management library we called xebia-management-extras that covers Jakarta Commons DBCP dataSource, util.concurrent ExecutorService, JMS (connection factory, Spring's DefaultMessageListenerContainer, etc), CXF and a @Profiled annotation to ease monitoring of business code.
All the details are at Google Code - Xebia Management Extras.
Hope this helps,
Cyrille
What do you do if have more than one cacheManager to monitor? I am using another for method level caching and I want to monitor that one as well.
ReplyDeleteThx
On that ManagementService bean you should set the destroy-method property to "dispose". Otherwise if your Spring context shuts down but your server doesn't (like in the case of a hot deploy), you'll get errors about duplicate MBeans.
ReplyDeleteGreat Article
ReplyDeleteOnline Java Training | Java Training in Chennai | Java Course in Chennai | Java 360
Respect and I have a tremendous proposal: How Many Home Renovation Shows Are There house and renovation show
ReplyDelete