Performance and scalability: Singleton across mulitiple JVMs in a cluster

  1. Hi,

    We have a requirement of caching a certain reference number, which we obtain from database through a synchronised method of a singleton object. This is implemented through a singleton, which works well in a single server. However, using it in a cluster (weblogic) set up this fails, as this would make up as many instances of the singleton as there are managed servers in the cluster.

    Is there any approach (design pattern), which would make a singleton application wide instead of JVM wide. Is this possible through rmi or ejb ?

  2. If your singleton is a hashmap you could use Tangosol Coherence (www.tangosol.com) to replicate it across a cluster. We're thinking about using it ourselves for a clustered cache.

  3. Please also see the clustered singleton example on our support forum site.


    Cameron Purdy
    Tangosol, Inc.
    Coherence: Easily share live data across a cluster!
  4. Its maybe possible to use ReadOnly concurrency strategy to handle this situation. You can specify the concurrency strategy of the ejb in the weblogic-ejb-jar.xml file.


    more info from about this issue:
  5. share object between JVMs[ Go to top ]

    I think you should read some in-depth artical about serialization, your situation is to share Objects between several JVMs. If you want to implement your own code, then you should reprogram all your source code. Otherwise you can use LDAP Server as a message borker to accomplish the intention.
  6. May be this ideas can help:

    1. implement singleton as RMI server object

    2. init (private static) instance reference of a Singleton by one obtained from JNDI tree rather then creation of a new object.

     I've never tryed this, so any comments appreciated
  7. Here is some background information about Java singletons:

  8. Be aware of the fact that if you use entity beans in a singleton pattern way, that an entity bean could be intantiated several times, depending on the implementation of the server.

    the "singleton behaviour" could be data-centric, which means the database is providing the singleton logic, as data is loaded and stored after every operation on the entity bean.

    on weblogic there is the possibility to make an entity readonly but you still have to use some additional weblogic specific options to ensure that weblogic is only instantiating one instance of the entity bean for all users of the same entity bean.

    another solution is to provide a rmi server implementation of your "singleton" and register it in the jndi-tree of for instance weblogic.

    the jndi-tree gets replicated withing a cluster in weblogic
  9. the jndi-tree gets replicated withing a cluster in weblogic

    It is not replicated reliably (nor synchronously nor with concurrency control) and the WebLogic documentation is explicit in its warnings that you should not use JNDI to replicate your data.


    Cameron Purdy
    Tangosol, Inc.
    Coherence: Easily share live data across a cluster!