File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes Singletons with Clustering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Singletons with Clustering" Watch "Singletons with Clustering" New topic

Singletons with Clustering

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
Am I the only one trying to use singletons with clustering ? It seems to be something which should have been done many times before, but detailed information on how it works does not seem to be readily available. I have posted two messages to the JBoss/Clustering forum (see and but I have yet to receive any more information on how to get this to work. Does anyone have any experience with this ?

This is my first attempt to use JBoss Clustering, and aside from the singletons it appears to be simple to setup and run a JBoss cluster. The only article on how this works for singletons,, which outlines creating a MBean to run as a singleton using the HASingletonController, isn't complete (no code for the MBean interface, no real direction on which cluster-service.xml to include the singleton and controller entries -- is it cluster-service.xml or cluster-examples-service.xml ?, do you package the SingletonMBean with other Mbeans in a SAR or in the EAR file ?, etc.), and I am having troubles not mentioned in the article.

The JBoss Clustering documentation I have shows that there are no clustering features available for Message-Drive EJBs -- so does this mean that running a singleton MDB, which runs fine in single JVM, as a singleton in the cluster is impossible ? If not then what else is required other than marking the MDB as <clustered> in the joss.xml ?

I am running JBoss 3.2.5. Any suggestions or information will be appreciated. Thanks in advance.

Frederico Melo

Joined: Mar 15, 2004
Posts: 24

At first you need to be completly sure about the needs to use a singleton. It should *NOT* be used on a multi-classloader enviroment since it's unique gaim (a single instance of a class on whole application) it's not garanteed on a multi-VM (multi-classloader) enviroment.
The only approach that can be used to emulate a singleton on a App. Server is exposing it on the JNDI context(wich can be done or not by JMX Mbeans). This way, your app has a unique point for acquiring a reference to a object(even across clustered app servers) in transparent way, and you can garantee that you factory exposed in JNDI context will only let one object copy exist.

best regards,


Frederico Melo<br />--------------<br />Software Architect<br />Sun Certified Enterprise Architect for J2EE<br />IBM Rational Unified Process Specialist
James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
So is it really not possible to have true singletons in a multi-VM (clustered) environment ? It seems that this is in fact possible, even though I have yet to get it to work for my application. There is a JBOSS/server/all/deploy-hasingleton directory for deploying singleton MBeans, and the previously mentioned article explains (though not completely) that it can be done. As far as using the cluster-wide HANamingService, I am doing this (I think) by removing the

from the InitialContext properties, and this makes the Context use port 1100, which is the HANamingService (cluster-wide JNDI). Is this not the case, or are there other things I should do as well ?

Thanks in advacnce for any further suggestions, as I am right near stumped on this.

I agree. Here's the link:
subject: Singletons with Clustering
It's not a secret anymore!