Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取EhCache中存储的对象_Java_Eclipse_Ehcache - Fatal编程技术网

Java 获取EhCache中存储的对象

Java 获取EhCache中存储的对象,java,eclipse,ehcache,Java,Eclipse,Ehcache,请帮助我理解并从EhCache中获取存储的对象。 我将Eclipse与TomcatWeb服务器一起使用。 Am使用ehcache-core.2.5.0.jar Execution Flow 1:(No Problem) 1,Start Eclipse and Run Applicaton 2,Call StoreServlet.java with value 10 --- this works 3,Call FetchServlet.java --- this

请帮助我理解并从EhCache中获取存储的对象。 我将Eclipse与TomcatWeb服务器一起使用。 Am使用ehcache-core.2.5.0.jar

Execution Flow 1:(No Problem)
1,Start Eclipse and Run Applicaton
2,Call StoreServlet.java with value 10   --- this works
3,Call FetchServlet.java                 --- this works
4,Call StoreServlet.java with value 20   --- this works
5,Call FetchServlet.java                 --- this works
6,Call ShutdownServlet.java              --- this works
即使我在重新启动Eclipse后尝试使用相同的方法,它也能正常工作, 如果我尝试重新启动SystemWindows并执行以下步骤,则不会从存储的磁盘中获取任何对象,但在Disk.data文件中包含所有存储的值

Execution Flow 2:(araises Problem)
1,Restart System,Start Eclipse and Run Applicaton
2,Call FetchServlet.java  --- no exception but objects count in cache is 0.
代码:

StoreServlet.java


您的缓存是如何配置的?@MikkelLøkke感谢您的回复。我没有任何xml。我正在执行有关getManager和getCache方法的所有配置。
CacheHelper.java :
public class CacheHelper {
private static Cache profitCache = null;
private static CacheManager manager = null;
private static CacheManager getManager()
{
    if(manager == null)
    {
        Configuration cacheManagerConfig = new Configuration();
        DiskStoreConfiguration disk =new DiskStoreConfiguration();
        disk.setPath("E:/Leo-Softwares/DataStore_ehCache");
        cacheManagerConfig.addDiskStore(disk);
        manager = CacheManager.create(cacheManagerConfig);
    }
    return manager;
}
private static void getCache()
{
    CacheConfiguration cacheconfig = new CacheConfiguration("Profit",1000);
    cacheconfig.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
    .eternal(true)
    .diskPersistent(true);
    profitCache = new Cache(cacheconfig);
    getManager().addCache(profitCache); 
}
public static void insert(Profit pro)
{
    if(profitCache == null)
    {
        getCache();
    }
    Element element = new Element(pro.getId(),pro);
    profitCache.put(element);
}
public static List getAllkeys()
{
    if(profitCache == null)
    {
        getCache();
    }
    return profitCache.getKeys();
}
public static Profit get(Object obj)
{
    if(profitCache == null)
    {
        getCache();
    }
    return (Profit)profitCache.get(obj).getObjectValue();   
}
public static void shutdown()
{
    if(manager != null)
    {
        manager.shutdown();
    }
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
    int i = request.getParameter("IVAL")!=null
            ?Integer.parseInt(request.getParameter("IVAL")):1000;
            System.out.println("IVAL:"+i);
    int j =i;
    int k = i +10;
    for(  j=i;j<k;j++)
    {
        Profit pro = new Profit();
        pro.setId(j);
        pro.setAmt(j+" AMT");
        CacheHelper.insert(pro);

    }
 System.out.println("j:::"+j);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
    List<Object> lst = CacheHelper.getAllkeys();
    Iterator<Object> iter = lst.iterator();
    int i = 0;
    while(iter.hasNext())
    {
        Object obj = iter.next();
        System.out.println("key:"+obj);
        Profit pro = CacheHelper.get(obj);      
        i++;
    }
    System.out.println("i in fetch@@@:"+i);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
    CacheHelper.shutdown();
}