This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes what is the actual advantage of Singleton program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "what is the actual advantage of Singleton program" Watch "what is the actual advantage of Singleton program" New topic
Author

what is the actual advantage of Singleton program

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
I want to know the advantages of singleton Design pattern

I f any one provides a sample program for the implementation of singleton then i can easily understand the aconcept

please provide me the links



thanx in advance


cinux


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

Try searching for "singleton design pattern" with Google and you'll find lots of information on the singleton design pattern.

Tutorial: Design Patterns
Singleton pattern (Wikipedia)
Simply Singleton - Navigate the deceptively simple Singleton pattern


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 302
With Singleton there will be only one instance of the class per jvm. Most often application specific things can go in singleton. For Ex: if you want to design an application such that application_state (can have values idle, active, on maintenance) need to be shared with many users you can keep this variable in a singleton class.

Advantages are by making a heavy weight class singleton, you are sharing a single instance of that class with many threads. This will save you resources and time.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
There isn't an advantage, which is why the singleton is becoming more widely known as the "singleton antipattern", as the design pattern hype subsides. First and foremost, a singleton does not exist, without solid proof of a finite universe, which we don't have. A singleton can exist within a given context; for example, a class loader, a JVM, many JVMs. In practice, I see most singletons implemented throughout a class loader, which is as simple as a global point of access to a hidden static field.

The singleton is usually implemented to prevent the need to pass a callback to clients. Specifically, some state can be updated in a singleton from one point in the application (or more correctly, the singleton context), and can be observed by another point, without either point knowing about each other (though indirectly through the singleton). This pattern can be traced to a requirement defect within a given context - one that we often assume. Since the notion of "design patterns" is losing the spotlight among the newer marketing hype, it is becoming more widely known that behind the gloss, is the opposite of what it was originally portraying itself as. Prefer to pass the callback type, and don't believe the hype - that rhymes I should approach a record label. </geekiness>


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the actual advantage of Singleton program
 
Similar Threads
singleton blocking
Tech Word Game
Is it possible to clone this object?
Creating a utility managed bean, to move common code and use from different beans?
singleton creattion!