[jboss-user] [Clustering/JBoss] - Re: How to create singletons?

shoeb1981 do-not-reply at jboss.com
Tue Dec 4 07:18:37 EST 2007


It is an interesting question. Following might be helpful

Before creating an instance of the singleton class, check if it exists in the system.properties. If it doesn't, create the instance and put that instance into system.properties map. 

For ex:
          if (System.properties.get("Single")==null) {
          Singleton single = new Singleton();
          System.properties.put("single", single);
          }


Second approach could be this:

Don't put the class in the classpath. Write your own classloader and specify the absolute location of the class. This way app server wouldn't be able to load the class automatically.


Hope that helps

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110153#4110153

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110153



More information about the jboss-user mailing list