如何从Coherence缓存中获取统计信息?

时间:2011-05-10 13:13:42

标签: java statistics oracle-coherence

我正在研究Oracle Coherence的客户端,他们感兴趣的一件事就是从中获取统计信息以了解使用模式等。

我知道我可以从JMX获取一些信息,但是我还提供了一个CacheStatistics接口,我想从中获取数据。但是,我无法看到如何从缓存对象获取其统计信息。

下面的代码是我的poc实现,我可以使用'cache'对象来放置和获取缓存中的值,有没有办法从缓存链接到相关的统计信息?我想我在某处遗漏了一些简单的事情......

    NamedCache cache = CacheFactory.getCache(cacheName);
    if(cache.isActive()){
            //Wrong because there's no link to the cache..
        SimpleCacheStatistics scs = new SimpleCacheStatistics();

        long hits = scs.getCacheHits();
        System.out.println("Cache hits:" +hits+"\n   : "+scs.toString());
    }

1 个答案:

答案 0 :(得分:0)

如果缓存是nearcache,那么您可以执行以下操作。还要检查API以获取backcache以查看其统计信息。

if (cache instanceof NearCache) {
    System.out.println("\tstatistics :" + ((LocalCache)((NearCache)cache).getFrontMap()).getCacheStatistics());
}