Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How implement the Singeltone design pattern in a clustered environment

Status
Not open for further replies.

royc75

Programmer
Jun 1, 2006
127
GB
Hello,

I need to manage a certain BigDecimal class member in a web application which will not be destroyed. This class member represents a key in a database which from few reasons I would like to manage on my own and I don't use EJBs.
In order to implement that, I have created a private static class member at the application and a get method in order for the other views to get it's value.
The get method checks if the value is null.
In case it is it queries the Database for the maximum value and return it + 1 to the requestor.
In case it is not null it simply increments the current value by 1 and returns it to the requestor.
According to my assumption, a DB query should happen only once since this member is static, yet when I monitor the application I see it queries the Database occasionally, which mean that the member has been destroyed.
After an investigating this I noticed thatthe application is running in a clustered envirinment with 3 servers which means that 3 classes are loaded (one per JVM), every class maintains own MAX_ID and therefore I get into collisions.
Suppose it is not possible to migrate the whole application to use EJBs, is there a solution for this case? Perhaps a certain J2EE Design Pattern to manage the key in a clustered environment which can expose the key generation method to my application?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top