3 Replies Latest reply on Apr 4, 2006 2:58 PM by genman

    PassivationInterceptor synchronization and behavior?

    genman


      In PassivationInterceptor, what is the purpose of this synchronization block?

       synchronized(this) {
       if(meth.equals(TreeCache.evictNodeMethodLocal)) {
       fqn=(Fqn)args[0];
       // evict method local doesn't hold the attrrbutes therefore we have to get them manually
       attributes= getNodeAttributes(fqn);
       // notify listeners to the cache instance that this node is about to be passivated
       cache.notifyNodePassivate(fqn, true);
       loader.put(fqn, attributes);
       if (cache.getUseInterceptorMbeans()&& statsEnabled)
       m_passivations++;
      
       }
      


      Certainly, m_passivations should be locked.

      Also ./src/org/jboss/cache/interceptors/ActivationInterceptor.java same sort of question.


        • 1. Re: PassivationInterceptor synchronization and behavior?

          I don't have an answer to your question but I can offer that the passivations counter code can be moved out of the synchronized block.
          if (cache.getUseInterceptorMbeans()&& statsEnabled)
          m_passivations++;


          Of course, this code must still be located within the conditional expression
          if(meth.equals(TreeCache.evictNodeMethodLocal))
          so moving it is probably only useful if you restructure the synchronization block.

          • 2. Re: PassivationInterceptor synchronization and behavior?
            hmesha

            The synchronization statement is needed to prevent multiple threads from trying to passivate or activate the node at the same time. However, we can switch to use BaseCacheLoaderInterceptor.obtainLoaderLock() to obtain locks. The same strategy used in CacheStoreInterceptor and CacheLoaderInterceptor. Please open a JIRA Issue for it and it'll be done.

            Cheers,

            Hany

            • 3. Re: PassivationInterceptor synchronization and behavior?
              genman


              I don't get how it was supposed to work, since if there were two evict calls, the two CacheLoader.put(Fqn, Map) calls would still happen, though serialized in some order. Is CacheLoader.put() externally synchronized? Maybe I misunderstood the code.

              http://jira.jboss.com/jira/browse/JBCACHE-533