4 Replies Latest reply on Jun 17, 2004 3:11 AM by a_amitgarg

    Behaviour of Singleton Classes while Clustering?

    poojac20

      Hi

      A simple question of Yes/No.
      In case my application targets clustering in future, is it O K to use writable singleton classes in the ear?

      There is a case here when a singleton's properties are modified at run time. Of course this modification dictates further bahaviour of the application. I am wondering, because clustered servers run in different JVMs, wud it result in separate instances of the singleton for different JVMs? (which though does not affect read-only cases, becomes an issue here)

      So, the question is, whether clustering tackles this issue or shud I avoid writable singletons in my application?

      --- Pooja

        • 1. Re: Behaviour of Singleton Classes while Clustering?
          ivelin.ivanov

          Singletons have the capability to share state across the cluster. It does not happen automatically, but you can enable it. The most straightworward way is to extend HASingletonSupport. Then implement startSingleton/stopSingleton. For the attributes that are supposed to be shared across the cluster use setDistributedState/getDistributedState instead of local member variables.

          Ivelin

          • 2. Re: Behaviour of Singleton Classes while Clustering?
            poojac20

            Thanx for the answer Ivelin.

            I did some search on this, & it seems its a relatively new addition.
            Read your article available at http://www.onjava.com/pub/a/onjava/2003/08/20/jboss_clustering.html on o'reilly and that clears certain things. But I have more questions.

            The example in this article talks about singleton services implemented as MBeans. I have a singleton which is a very simple class .... no frills attached, and certain objects get added/deleted from it, which are contained in the singleton in a hashmap.

            From the article I could not gather if it is neccesary to create an MBean for the purpose? but then the article was not talking about the support class u mentioned in ur post. Can u direct me to some article which outlines this basic usage cuz I can't find it (or is it only available in the paid docs :D)? Or let me know if the MBean use is mandatory?
            Thanx in advance
            --- Pooja.

            • 3. Re: Behaviour of Singleton Classes while Clustering?
              ivelin.ivanov

              Tou can use the Distributed State Manager facility directly outside of an MBean. It is described in the JBoss Clustering book.

              Ivelin

              • 4. Re: Behaviour of Singleton Classes while Clustering?
                a_amitgarg

                Can anybody tell me where can i find the api for the class HASingletonSupport?