本文介绍了通过JMX监视Ehcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Spring + Hibernate中实现了应用程序。要优化ORM操作,请紧跟



您知道我是否错过了一些启用功能统计信息?

解决方案

问题出在您只是创建 ManagementService 但不初始化它。



您的 managementService 方法需要调用 init ()创建的 ManagementService 方法。



除非您有效地需要访问 ManagementService 用于其他目的,不需要将其作为Bean公开,您可以使用静态 ManagementService.registerMBeans(CacheManager,MBeanServer ,布尔值,布尔值,布尔值,布尔值) c $ c> ehCacheManagerFactory()或 ehCacheManager()方法。



静态方法创建 ManagementService 并将其初始化。


I have implemented application in Spring + Hibernate. To optimize ORM operations I have followed by this tutorial to enable monitoring for Ehcache:

@EnableWebMvc
@EnableSpringDataWebSupport
@EnableCaching
...
public class SpringWebConfig extends WebMvcConfigurerAdapter {

    ....

    @Bean
    public EhCacheCacheManager ehCacheManager() {
        EhCacheCacheManager cacheManager = new EhCacheCacheManager();
        cacheManager.setCacheManager((net.sf.ehcache.CacheManager) ehCacheManagerFactory().getObject());

        return cacheManager;
    }

    @Bean
    public EhCacheManagerFactoryBean ehCacheManagerFactory() {
        EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
        cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
        cmfb.setShared(true);
        return cmfb;
    }

    @Bean
    public ManagementService managementService() {
        return new ManagementService(ehCacheManager().getCacheManager(), mBeanServer(), true, true, true, true);
    }


    @Bean
    public MBeanServer mBeanServer() {
        MBeanServer bean = ManagementFactory.getPlatformMBeanServer();
        return bean;
    }
}

However I cannot see any ehache beans in jConsole:

Do you know if I missed something to enable statistics?

解决方案

The issue comes from the fact that you are simply creating the ManagementService but not initialising it.

Your managementService method needs to invoke the init() method on the created ManagementService.

Unless you effectively need access to the ManagementService for other purposes, exposing it as a bean is not required and you may replace this by a usage of the static ManagementService.registerMBeans(CacheManager, MBeanServer, boolean, boolean, boolean, boolean) either inside the ehCacheManagerFactory() or ehCacheManager() methods.

The static method creates the ManagementService and initialises it.

这篇关于通过JMX监视Ehcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 16:51