This discussion is archived
5 Replies Latest reply: Feb 25, 2013 1:49 AM by Jonathan.Knight RSS

SafeNamedCache was explicitly released error

729195 Newbie
Currently Being Moderated
Hi there, we are using Coherence 3.7.1.1 within Weblogic 11.1.1.6.0

We have some Java code deployed on the server:

public Session create(User user) {
NamedCache sessionCache = CacheFactory.getCache(SESSION_CACHE_NAME);
Session session = new Session(user);
sessionCache.put(session.getSessionId(), session, getConfig().getSessionTTL());
CacheFactory.releaseCache(sessionCache);
return session;
}

Every now and again it fails on the sessionCache.put method (line 71) with SafeNamedCache was explicitly released.

Error stack:
SafeNamedCache was explicitly released</message> <ns2:stackTrace>
<ns2:frame class="com.tangosol.coherence.component.util.SafeNamedCache" file="SafeNamedCache.CDB" line="23" method="ensureRunningNamedCache"/>
<ns2:frame class="com.tangosol.coherence.component.util.SafeNamedCache" file="SafeNamedCache.CDB" line="1" method="getRunningNamedCache"/>
<ns2:frame class="com.tangosol.coherence.component.util.SafeNamedCache" file="SafeNamedCache.CDB" line="1" method="put"/>
<ns2:frame class="mywes.security.sessions.impl.SessionDao" file="SessionDao.java" line="71" method="create"/>

Any ideas why this would be happening? And what can be done to stop this from happening?

Regards
Robert
  • 1. Re: SafeNamedCache was explicitly released error
    936311 Newbie
    Currently Being Moderated
    You are explicitly releasing the cache

    CacheFactory.releaseCache(sessionCache);

    So the error you are getting is expected.


    Thanks,
    Manish
  • 2. Re: SafeNamedCache was explicitly released error
    Jonathan.Knight Expert
    Currently Being Moderated
    Hi,

    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.

    JK
  • 3. Re: SafeNamedCache was explicitly released error
    Jonathan.Knight Expert
    Currently Being Moderated
    Manish,

    The error is not expected necessarily. As far as I know, if you called releaseCache then next time you call getCache a new local instance of the cache would be created.

    JK
  • 4. Re: SafeNamedCache was explicitly released error
    729195 Newbie
    Currently Being Moderated
    Hi Jonathan,

    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.

    Regards Rob
  • 5. Re: SafeNamedCache was explicitly released error
    Jonathan.Knight Expert
    Currently Being Moderated
    Hi,

    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.

    JK

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points