aspose file tools*
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
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: 14435
    
  23

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 8 API documentation
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton Problem---- Real Problem