• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Singleton Pattern

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone help me explain "How a Singleton pattern implemented in JVM"?
Thanks
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I don't fully understand the question. Could you please elaborate? What do you need this for?
 
Arvind Varma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been recently asked about singleton pattern which i aptly explained. Following that I was asked "how is singleton pattern implemented in JVM?"
I know that we can implement the singleton pattern for class A by checking if an instance is already present and then create it.
But i myself did not get that question..so posted it if anyone of you could help me out...
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are numerous variants. You can use lazy instantiation, so the Singleton is created only the first time you call getInstance(). In a web container, class reloading may mess up a Singleton based on static variables and you may be better off using the application context instead. This example allows only one instance of a class; sometimes you want one instance per possible state, the GoF book uses the example of using objects to represent the 26 letters of the alphabet; your Singleton will then have 26 instances, one for each letter.
- Peter
[ December 30, 2002: Message edited by: Peter den Haan ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic