This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Singleton vs application context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Singleton vs application context" Watch "Singleton vs application context" New topic

Singleton vs application context

shaju joseph
Ranch Hand

Joined: Jun 28, 2001
Posts: 30
What's the difference between making a class singleton and setting a class variable in the application context ? If I make a class singleton , is it available till the server is shutdown ?
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
Application context is actually just "WAR-context" whereas singleton context is JVM wide(If your JAR is put in server's class path).
Stuffs being stored in ServletContext will be unloaded, and reloaded when you reload the WAR, or updates the WAR. Singletons in the JVM will not be reloaded until you shutdown the server.
I agree. Here's the link:
subject: Singleton vs application context