This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Spring Singleton or Java Singleton

 
Ranch Hand
Posts: 401
2
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference in Spring Singleton and Java Singleton? I understand that Spring Singleton is 1 instance per spring container per JVM while Java Singleton is 1 instance per JVM.

I am just wondering in Spring MVC application, how can we have more than 1 spring containers?
 
Bartender
Posts: 1164
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be more precise, a java singleton is an unique instance per classloader, and a JVM may have different classloaders.
Beside this, I can't think of other important differences. Maybe, to develop a Spring singleton is easier than developing a 'regular' java singleton, just because it's only matter to define a scope = singleton on a bean and let the container do the work for you.
 
author & internet detective
Posts: 39392
763
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:What is the difference in Spring Singleton and Java Singleton?


Not all Spring singletons are Java singleton. A Java singleton is coded in a way that prevents code from creating two instances of the object.

A Spring singleton just means that Spring will only create one object. There's nothing to stop other Java code from creating other instances. Think of it as object pooling/caching.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!