Java – ehcache data view via JMX

Is there any way to view the data / objects stored in ehcache through JMX? I found that it's just cache statistics, but I need to look at the object structure

Solution

If this is what you need, you can build it, but it is not available in the ehcache JMX implementation I don't want it because I don't know whether the objects stored in ehcache can be displayed through JMX If you know they are, of course you can create an MBean to expose the contents of the cache when giving a reference to ehcache, CacheManager or cache

Remember that unless you use memory only caching, the objects in the cache will not be in memory but on disk, or if you use clay, they may be located on a remote server In addition, it is sometimes more efficient to store Java objects in serialized form If you do, viewing the data will require deserialization

If you just want to see these objects when debugging problems, I'll consider relying on the debugger available in a good ide Both NetBeans and eclipse have debuggers that can be used to view cached content I often do this

Since you marked this question with "spring", I assume you are using spring It's easy to create an MBean in spring You just need to add the exporter bean to the context and make your MBean implement an interface with the same name as your object, but add the MBean to the end Here is an example:

applicationContext. In XML:

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" 
      p:autodetect="true"/>
<bean name="FOO:name=foo" class="com.foo.test.Foo"/>

Foo. java:

package com.foo.test;

public class Foo implements FooMBean {
  private String name;

  ...

  @Override
  public String getName() {
    return name;
  }

  @Override
  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void printName() {
    System.out.println(name);
  }
}

FooMBean. java:

package com.foo.test;

public interface FooMBean {
  public String getName();
  public void setName(String name);
  public void printName();
}

In this example, the "foo" object will be exposed as a JMX MBean with a property named "name" and an operation named "printname" The name of the MBean will be: "foo: name = foo" You can customize all of these behaviors See: http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/htmlsingle/#jmx -exporting

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>