3 Replies Latest reply on Aug 26, 2014 11:46 PM by phillip.atkinson

    Best practices for start() and stop() ?

    phillip.atkinson

      Hi,

       

      I'm wondering what the best practices for using the start() and stop() methods are for a Cache / CacheManager ?

       

      For example, in my app which uses several named caches, on startup every node does something like this:

       

      CacheContainer cacheManager = new DefaultCacheManager(config.xml);

      cacheManager.getCache("cache1").start();

      cacheManager.getCache("cache2").start();

       

      Is this correct / ok?

       

      Then when a node shuts down, I'm not sure if that particular node needs to call cacheManager.stop() -> this would stop the cacheManager, also stopping all caches ? Should every node in a cluster do this when it shuts down (to gracefully stop any in-process data replication, etc), or is it not necessary?

        • 1. Re: Best practices for start() and stop() ?
          nadirx

          When you get a cache from a CacheManager using the getCache(String) method, it will be returned "started", so there is no need to invoke start() on it.

          You MUST invoke CacheManager.stop() at node shutdown as that will stop all caches and release all global resources (thread pools, mbean bindings, etc) in a clean way,

          • 2. Re: Best practices for start() and stop() ?
            rvansa

            If you really want to stop *everything* you also need to stop transactional services, calling

             

            TxControl.disable(true);

            TransactionReaper.terminate(true);

             

            from com.arjuna.ats.arjuna.coordinator package. Otherwise, few threads could be hanging in your app (it's not responsibility of Infinispan to cleanup after TransactionManager).

            • 3. Re: Best practices for start() and stop() ?
              phillip.atkinson

              Ok thanks for the input! I was worried that calling cacheManager.stop() on one node would globally stop the caches / CacheManager in the cluster, thus keeping other nodes from using the caches / CacheManager. I poked around in the source code, and it seems ok (as well as testing this actual scenario). So all's well .

               

              Thanks again!