4 Replies Latest reply on Aug 20, 2004 11:01 PM by ben.wang

    Thread safety?

    mfrost

      We are planning to use the TreeCache in our clustered production JBoss environment.

      We will be invoking the TreeCache methods (via JMX MBean) from a Stateless Session Bean.

      Are there any threading issues to consider? We have currently not placed any synchronization around any method calls to TreeCache.

      Many thanks.

      mark

      Code example from SLSB:

       public void put(String cacheSystemName, CacheKey key, VersionedXml value) throws CacheException {
       log4j.debug("TreeCache.put()");
      
       //put into cache
       Fqn fqn = new Fqn(this.rootFqn, ((FqnCacheKey) key).getFqn());
       Object[] args = new Object[] {fqn, STANDARD_KEY, value};
       String[] sig = new String[] {FQN_CLASS_NAME, OBJECT_CLASS_NAME, OBJECT_CLASS_NAME};
      
       //Invoke the put() method
       _invoke("put", args, sig);
       }
      
       private Object _invoke(String methodName, Object[] args, String[] sig) throws CacheException {
       try {
       return JBossUtils.locateJBoss().invoke(cacheService, methodName, args, sig);
       } catch (Exception ex) {
       throw new CacheException("Error invoking method " + methodName + " on TreeCache", ex);
       }
       }
      


        • 1. Re: Thread safety?
          belaban

          You should be fine; TreeCache is thread-safe.
          Bela

          • 2. Re: Thread safety?
            mfrost

            many thanks bela

            mark

            • 3. Re: Thread safety?
              visionlink

              there are two queues in a Region: nodeQueue and eventQueue. i understand that the BoundedBuffer is thread-safe. however, since there are two queues that are being operated on, it seems like there is a potential race in Region.putNodeEvent and LRUAlgorithm.processQueues. is there a bit of higher-level synchronization going on that i don't see?

              thanks for any insight.

              • 4. Re: Thread safety?

                This is indeed a potential problem that I have been planned to correct. :-) Anway, I have just refactored the eviction policy part and checked them into jboss-head. The fix will be available in release 1.1.

                Thanks,

                -Ben