Bookmark Topic Watch Topic
  • New Topic

Singleton Problem---- Real Problem

 
SharajIndia Anand
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
Identify the problem within this snippet of Java/C# code. (This is not a trick question � there is a potential real problem in using this code)

class Singleton
{
public static Singleton Instance() {
if (_instance == null)
_instance = new Singleton();
return _instance;
}
protected Singleton() {}
private static Singleton _instance = null;
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is this an exam question that you don't know the answer to yourself?

Hint: Think about what might happen if multiple threads call Singleton.getInstance() at the same time.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Interesting that you posted exactly the same question as someone else. Can you tell us where this question comes from?
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
In any event, the issue is covered elsewhere, so I'll close this one.

For those of us who are interested, we can eventually find out the source of the question, I'm sure.
 
    Bookmark Topic Watch Topic
  • New Topic