• 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Spring Singleton or Java Singleton

 
Ranch Hand
Posts: 427
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: 1259
39
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: 39956
804
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.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic