File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton two or more instances

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start a second JVM...
 
Stephan van Hulst
Bartender
Pie
Posts: 4830
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic