001
014
015 package com.liferay.portal.cache.ehcache;
016
017 import com.liferay.portal.kernel.util.ReflectionUtil;
018 import com.liferay.portal.util.PropsValues;
019
020 import java.lang.reflect.Field;
021
022 import java.util.concurrent.ScheduledThreadPoolExecutor;
023
024 import net.sf.ehcache.CacheManager;
025 import net.sf.ehcache.config.Configuration;
026
027
030 public class CacheManagerUtil {
031
032 public static CacheManager createCacheManager(Configuration configuration) {
033 CacheManager cacheManager = new CacheManager(configuration);
034
035 try {
036 ScheduledThreadPoolExecutor scheduledThreadPoolExecutor =
037 (ScheduledThreadPoolExecutor)_STATISTICS_EXECUTOR_FIELD.get(
038 cacheManager);
039
040 scheduledThreadPoolExecutor.setCorePoolSize(
041 PropsValues.EHCACHE_CACHE_MANAGER_STATISTICS_THREAD_POOL_SIZE);
042 }
043 catch (Exception e) {
044 throw new RuntimeException(e);
045 }
046
047 return cacheManager;
048 }
049
050 private static final Field _STATISTICS_EXECUTOR_FIELD;
051
052 static {
053 try {
054 _STATISTICS_EXECUTOR_FIELD = ReflectionUtil.getDeclaredField(
055 CacheManager.class, "statisticsExecutor");
056 }
057 catch (Exception e) {
058 throw new ExceptionInInitializerError(e);
059 }
060 }
061
062 }