本文整理汇总了Java中net.sf.ehcache.Ehcache.setSampledStatisticsEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java Ehcache.setSampledStatisticsEnabled方法的具体用法?Java Ehcache.setSampledStatisticsEnabled怎么用?Java Ehcache.setSampledStatisticsEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.Ehcache
的用法示例。
在下文中一共展示了Ehcache.setSampledStatisticsEnabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import net.sf.ehcache.Ehcache; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws CacheException, IOException {
// If no cache name given, use bean name as cache name.
String cacheName = getName();
if (cacheName == null) {
cacheName = this.beanName;
setName(cacheName);
}
// If no CacheManager given, fetch the default.
if (this.cacheManager == null) {
if (logger.isDebugEnabled()) {
logger.debug("Using default EhCache CacheManager for cache region '" + cacheName + "'");
}
this.cacheManager = CacheManager.getInstance();
}
synchronized (this.cacheManager) {
// Fetch cache region: If none with the given name exists, create one on the fly.
Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
if (cacheExists) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EhCache cache region '" + cacheName + "'");
}
rawCache = this.cacheManager.getEhcache(cacheName);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Creating new EhCache cache region '" + cacheName + "'");
}
rawCache = createCache();
rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader);
}
if (this.cacheEventListeners != null) {
for (CacheEventListener listener : this.cacheEventListeners) {
rawCache.getCacheEventNotificationService().registerListener(listener);
}
}
// Needs to happen after listener registration but before setStatisticsEnabled
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
// Only necessary on EhCache <2.7: As of 2.7, statistics are on by default.
if (setStatisticsAvailable) {
if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
rawCache.setSampledStatisticsEnabled(true);
}
}
if (this.disabled) {
rawCache.setDisabled(true);
}
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
}
this.cache = decoratedCache;
}
}