大家好, 我目前的要求是使用 EhCache 存储和读取记录。我是 EhCache 实现的新手。我已阅读 EhCache 文档并开始实施。我已经完成了记录插入部分和阅读部分。插入记录时,将创建 *.data nd *.index 文件。以下是代码。
public class Driver
{
public static void main(String[] args) {
CacheManager cm = CacheManager.create("ehcache.xml");
Cache cache = cm.getCache("test");
// I do a couple of puts
for(int i=0;i<10;i++){
cache.put(new Element("key1", "val1"));
cache.flush();
}
System.out.println(cache.getKeys());
for(int i=0;i<10;i++){
Element el = cache.get("key"+i);
System.out.println(el.getObjectValue());
}
cm.shutdown();
}
}
现在问题是cm.shutdown()。如果我评论这一行并注释掉插入部分并运行程序意味着,无法检索记录并且 *.index 文件也被删除。所以在实际情况下,如果程序突然停止意味着我们无法在启动后读取记录。我想知道为什么文件被删除以及为什么在这种情况下我无法读取记录...控制台中出现的异常是
net.sf.ehcache.util.SetAsList@b66cc
Exception in thread "main" java.lang.NullPointerException
at Driver.main(Driver.java:29)...
需要任何输入请..