4

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

我知道我可以从 JMX 获得一些信息,但是还提供了一个 CacheStatistics 接口,我想从中获取数据。但是我看不出我应该如何从拥有一个缓存对象到获取它的统计信息。

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

    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());
    }
4

1 回答 1

0

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

if (cache instanceof NearCache) {
    System.out.println("\tstatistics :" + ((LocalCache)((NearCache)cache).getFrontMap()).getCacheStatistics());
}
于 2011-10-11T04:37:55.770 回答