tags:

views:

122

answers:

1

Hi All, I am using EHCache 1.5.0 on a webapp running on WebLogic 9.1 instance and 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

code that causes this issue

getMyCache().isKeyInCache(cacheKey)

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


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


The error is as follows Stackoverflow:

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) ......

There is nothing else in the log indicating the cause for the nullpointer 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. Thanks Srini

A: 

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).

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.

Alex Miller