• 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

what is singleton, how to implement it

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i want to learn some core java design patterns .can anyone tell me what is singleton,how to write singleton, where exactly this fits in the application development pls explain in detail with example.

thank you very much
mohan dodderi
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See http://faq.javaranch.com/view?SingletonPattern

Most importantly: *don't* use it, unless you are very sure that there isn't a better design.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically, I wouldn't implement the singleton in the manner mentioned in the java ranch faq posted. Usually there is no reason for lazy initialization of the Singleton. Here is a thread on the sun java forum where I discuss an alternative approach to the singleton pattern.

http://forum.java.sun.com/thread.jspa?forumID=31&messageID=1575569&threadID=371610

Here is the code mentioned in the thread

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I vote with Steve ... that's far and away the simplest and safest way to instantiate your singleton. And with Ilja ... we often think we need Singleton when we might not. They can have some negatives that you have to work to avoid. Do you want to describe your design a bit more and see if we all chime in with alternatives?
 
mohan dodderi
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all for your invaluable replies.

thanking you
mohan dodderi
 
Seriously? That's what you're going with? I prefer this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic