【发布时间】:2010-07-14 23:38:34
【问题描述】:
我有一个 Java 应用程序在 Linux 上的 JDK 1.6.0_17 上运行。我正在使用 ehcache 2.1.0,带有一个非常简单的 ehcache.xml 文件:
<diskStore path="/ext/ehcache"/>
<defaultCache
overflowToDisk="true"
diskPersistent="true"
maxElementsInMemory="10000"
maxElementsOnDisk="1000000000"
eternal="true">
</defaultCache>
在我的 java 应用程序中,我有以下代码:
private static final String CACHE_NAME = "APP";
public static void init() {
CacheManager.create();
final CacheManager manager = CacheManager.getInstance();
manager.addCache(CACHE_NAME);
}
private static Cache getCache() {
final CacheManager manager = CacheManager.getInstance();
return manager.getCache(CACHE_NAME);
}
public static Object get(String key) {
final Cache cache = getCache();
final Element element = cache.get(key);
return (element != null) ? element.getValue() : null;
}
private static void put(String key, Object value) {
final Cache cache = getCache();
final Element element = new Element(key, value);
cache.put(element);
}
如果我删除磁盘存储文件 (/ext/ehcache) 并启动我的应用程序,我可以看到正在写入磁盘存储文件。如果我在应用程序运行时对文件执行“ls -l”,“ls -l”表明文件大小随着时间的推移而变大。
然后我使用“kill -15”(SIGTERM)停止我的 java 应用程序。然后我重新启动我的 java 应用程序,它似乎启动正常。 Java 应用程序继续将数据存储到 ehcache 中,但很长一段时间以来,磁盘存储文件从未增长。 “ls -l”总是显示相同的文件大小。等待数小时后,文件确实又开始增长了。
我猜磁盘存储中的所有内容都变得无效,并且文件的内容正在重新填充。如果是这样,为什么磁盘存储中的所有内容都无效?我想在应用重新启动之间保持这些数据可用。
【问题讨论】:
标签: java persistence ehcache