This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Singleton Problem---- Real Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Singleton Problem---- Real Problem

SharajIndia Anand
Greenhorn

Joined: Sep 19, 2005
Posts: 2
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Oct 25, 2000
Posts: 7292

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.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
wood burning stoves
 
subject: Singleton Problem---- Real Problem
 
Similar Threads
"POTENTIAL PROBLEM" in following prg ?
prb with follwing prg
Core Java
what is the use of this " static A a = new A() "
"Potential Problem" in following prg ?