Singleton instance

Hi all. I have developed a web application based on Struts 1.3.8 and the application is deployed on JBoss 4.0.5.GA.

I have four application configuration parameters that I need to access in different areas of my application. My solution has been to create a configuration object that is a singleton instance. When the application is loaded by the application server, I populate the singleton object with configuration parameters that are read from a database via my DAO. The application functions correctly, however, I am concerned about the use of the singleton pattern to store and provide the application configuration parameters. I have read that the JVM has one instance of the singleton object as expected. However, multiple JVMs will have multiple instances of the singleton object.

My questions are as follows:

1. Is the use of a singleton object for the purposes of storing application configuration parameters a good idea in a web application?

2. Is it possible that there will be multiple JVMs for the JBoss application server and therefore multiple instances of the singleton object?

3. Is there some other way to handle application configuration parameters?

Many thanks, Kenny

[1232 byte] By [krodmana] at [2007-11-27 11:34:46]
# 1

singleton will work fine for ur case because JBoss will run on only one JVM.

u can use servlet context for storing application configuration parameters.

gopiponnegantia at 2007-7-29 16:59:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

singleton object is a good idea to store application configuration.

this way the same configuration object can be used in web as well as ejb tier.

you need to take care if you are using jboss in clustered environment.

preetam_picta at 2007-7-29 16:59:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I would create the object and save it as an application scope object, so that it can be initialized only once and shared across all sessions. I'm assuming, although I've never proved it, that if the environment were clustered, your application object would be replicated and available.

jackett_dada at 2007-7-29 16:59:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

in a clustered environment a separate instance will exist for each JVM in the cluster.

You'll (if needed) have to do a lot of black magic to get those objects synchronised between the machines in the cluster.

jwentinga at 2007-7-29 16:59:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

in clustered env JBoss will take care of transfering objects from one cluster to another cluster by using synchronization . so no problem

gopiponnegantia at 2007-7-29 16:59:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...