This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Singleton instance lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Singleton instance lifecycle" Watch "Singleton instance lifecycle" New topic

Singleton instance lifecycle

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243


How is the lifecycle of a POJO Singleton instance managed in an app / web server. I have a Singleton class and this will be accessed by some components which are under the control of an app server. Now upon first request for this Singleton instance, the ClassLoader will load the class in memory, create an instance and is this instance retained in the memory untill the app server is brought down?

SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Rob Spoor

Joined: Oct 27, 2005
Posts: 19543

Until the class is unloaded, which usually indeed is when the app server (or JVM for standalone apps) is shut down.

How To Ask Questions How To Answer Questions
Monu Tripathi

Joined: Oct 12, 2008
Posts: 1369

Even I asked this question once!

[List of FAQs] | [Android FAQ] | [Samuh Varta]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243

Thanks for the information.
I agree. Here's the link:
subject: Singleton instance lifecycle
Similar Threads
Singleton - Diff WAR files - same JVM - instances?
Singletons and memory leaks
Singleton and java garbage collection...and issue?
ServiceLocator/Singleton as an cache in clustered environment
Weblogic cluster question