• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Best way to instantiate a Singleton in a web app?

I have a POJO singleton that implements the observer pattern. I need it to register itself with a number of objects that implement observable. This is in a web (Struts) application. What's the best way to instantiate the singleton when the application starts up?
0
FeralCTO
Asked:
FeralCTO
1 Solution
 
objectsCommented:
you could that it from a servlet and store it in the ServletContext
0
 
FeralCTOAuthor Commented:
So are you suggesting I implement a servlet that loads at startup and then instantiate my singleton in the init( ) method?
0
 
objectsCommented:
yes
0
 
jpolin1Commented:
Probably want to make the constructor on the singleton synchronized too.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
No, I think its better to make the getInstance () synchronized. Anyway, we don't know how it is implemented - maybe it already is the right way.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now