通过高速缓存键查找时出现EHCache错误 [英] EHCache error on looking up by cache key

查看:107
本文介绍了通过高速缓存键查找时出现EHCache错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WebLogic 9.1实例上运行的Webapp上使用EHCache 1.5.0。从缓存中获取元素或检查缓存中是否存在某个项目时,偶尔会遇到以下错误。还有其他人看到过这个问题吗?有关如何解决此问题的任何建议都很好。

I am using EHCache 1.5.0 on a webapp running on a WebLogic 9.1 instance. Once in a while I run into the following error while getting an element from cache or while checking if an item exists in cache. Has anyone else seen this issue? Any suggestions on how to fix this would be great.

导致此问题的代码:

getMyCache().isKeyInCache(cacheKey)

ehcache配置:

ehcache configuration:

maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="true"

I我正在使用Spring获取CacheManager的实例,这是我的bean定义:

I am using Spring to get an instance of CacheManager and here is my bean definition:

   <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation"><value>classpath:ehcache.xml</value></property>
    </bean>

错误如下:

java.lang.NullPointerException 
                at net.sf.ehcache.Cache.isElementInMemory(Cache.java:1962) 
                at net.sf.ehcache.Cache.isKeyInCache(Cache.java:2075) 
                at com.test.services.impl.ContentServicesImpl.getContentItemFromCache(ContentServicesImpl.java:260) ......

日志中没有其他内容指示在缓存中查找键时导致NullPointerException的原因。

There is nothing else in the log indicating the cause for the NullPointerException on looking up a key in cache.

任何指针,有关如何解决此问题的建议将不胜感激。这种情况并不一致,似乎是在一个环境中随机发生的。

Any pointers, suggestions on how to fix this will be greatly appreciated. This does not happen consistently, seems to happen randomly in one environment.

推荐答案

给出堆栈跟踪,看来调用线程看到Cache中的MemoryStore为空(这是不可能的)。我暗中怀疑这可能是CacheManager创建代码(双重检查锁定)或Cache本身中的内存可见性问题。对于Ehcache 1.7.1,我们已经解决了许多此类字段可见性问题(尚未发布,但已经过了几周)。

Given the stack trace, it seems that the calling thread is seeing a Cache with a null MemoryStore (which shouldn't be possible). I have a sneaking suspicion that this might be a memory visibility issue in either the CacheManager creation code (double-checked locking) or the Cache itself. We've tightened up a lot of those field visibility issues for Ehcache 1.7.1 (not out yet but in a few weeks).

这很难给出一个确定的解决方法,但是一个糟糕的想法是添加一些弹簧初始化,以确保在启动期间的早期只有一个线程构造了CacheManager。如果这样可以解决问题,则可以为上述理论提供一些保证。

That makes it hard to give a definite fix but one crappy idea would be to add some spring initialization that guaranteed early during startup that only one thread constructed the CacheManager. If that made the problem go away, it would lend some credence to the above theory.

这篇关于通过高速缓存键查找时出现EHCache错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆