aspose file tools*
The moose likes Java in General and the fly likes Singleton two or more instances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Singleton two or more instances" Watch "Singleton two or more instances" New topic
Author

Singleton two or more instances

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, The following is asked me several times during the interview
Question : Can we have singleton with 2 instances or 3 instances or more ? How to achieve that ?
My Answer : It cannot be more than 1 instance.
But interviewers are never happy with my answer even though I gave them the Singleton code. Please let me know how to get it. Please post code which helps me a alot.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

How does singleton allows the flexibility to create more objects if the situation changes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10911
    
  12

Start a second JVM...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3370
    
    9
Personally I've always thought of the Singleton pattern as one that generally limits the amount of instances created, but not necessarily to a single instance. The name is misleading, but the general case makes more sense for a pattern.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

fred rosenberger wrote:Start a second JVM...

Or just use a second class loader?

It could be that they're thinking about distributed applications...in which case unless you're doing something clever there's nothing to stop the separate components each creating an instance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton two or more instances
 
Similar Threads
why stateless bean is not singleton
Java class
Using a Singleton for a DAO class
Issues in Singleton Design Pattern
Understanding singleton pattern