Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Singleton Pattern

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
    Bookmark Topic Watch Topic
  • New Topic