aspose file tools*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

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: 306
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 creattion!
Is it possible to clone this object?
Tech Word Game
singleton blocking
Creating a utility managed bean, to move common code and use from different beans?