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?
LVL 1
FeralCTOAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.