This content has been marked as final. Show 5 replies
I assume your code is running inside some sort of Web Application inside WebLogic and is therefore multi-threaded - that is, multiple threads could call this code at the same time. In that case it may be that something like this happens...
Thread 1: NamedCache sessionCache = CacheFactory.getCache(SESSION_CACHE_NAME);
Thread 2: NamedCache sessionCache = CacheFactory.getCache(SESSION_CACHE_NAME);
Thread 1: Session session = new Session(user);
Thread 2: Session session = new Session(user);
Thread 2: sessionCache.put(session.getSessionId(), session, getConfig().getSessionTTL());
Thread 2: CacheFactory.releaseCache(sessionCache);
Thread 1: sessionCache.put(session.getSessionId(), session, getConfig().getSessionTTL());
As the cache factory and cache are singletons inside Coherence if Thread 2 has called releaseCache before Thread 1 does the put then the put will fail as the cache has been released.
That does make sense, so now how to solve that issue.
I guess I could remove the call to releaseCache() - although I am not sure of the consequences of not calling this.
Alternatively, I could put some retry logic in, have a catch on SafeNamedCache explicity released, then retry getCache(), put(), releaseCache().
Any other options?
Thanks for the help.
I was curious why you were calling releaseCache as it isn't something I would do. Reading the JavaDocs I can see that it makes sense to release the caches in an application that runs in an App Server so that the class loader can be released and an application re-deployed. It is a long time since I wrote a Coherence web-app but if I remember correctly we added some sort of application life cycle listener that was triggered when the application was shut down which called CacheFactory.shutdown() to release everything.