[jboss-dev-forums] [Design of JBossCache] - PojoInstance: ref count & notification

supi do-not-reply at jboss.com
Sun Apr 8 11:13:24 EDT 2007


Hi, I am trying to build an adapter on top of CacheListener to create (to me useful) Pojo notifications. Unfortunately, I cannot determine if a pojo is being multi-attached or detached because PojoInstance's ref count is the same in local pre and post notification (IMO a bug). The problem is in InternalHelper:


  |    /**
  |     * Increment reference count for the pojo. Note that this is not thread safe or atomic.
  |     */
  |    int incrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
  |    {
  |       PojoInstance pojoInstance = getAopInstance(originalFqn);
  |       if (pojoInstance == null)
  |          throw new PojoCacheException("InternalDelegate.incrementRefCount(): null pojoReference for fqn: " + originalFqn);
  | 
  |       int count = pojoInstance.incrementRefCount(referencingFqn);
  |       // need to update it.
  |       put(originalFqn, PojoInstance.KEY, pojoInstance);
  |       return count;
  |    }
  | 

It is stated that the method is not thread safe but the instance's incrementRefCount and decrement methods are in fact synchronized. So, can I just clone the instance, increment and put or do I need to synchronize the whole thing? Shouldn't it be locked anyway, where does this happen? Are there any other effects that I should be aware of that prevent us from doing:

  |       PojoInstance updatedInstance = (PojoInstance)pojoInstance.clone();
  |       int count = newInstance.incrementRefCount(referencingFqn);
  |       // need to update it.
  |       put(originalFqn, PojoInstance.KEY, updatedInstance);
  | 

Thanks,
Basil



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035598#4035598

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035598



More information about the jboss-dev-forums mailing list