Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-11-2009, 05:42 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default PLS PLS PLS PLS solve this
Identify the problem within this snippet of Java/C# code implementing Singleton Design Pattern. (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;
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-11-2009, 05:47 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
Quote:
snippet of Java/C# code
? which is this supposed to be, Java or C#? They are similar but not one and the same.

Quote:
Identify the problem ...
Could this be homework? Even if it isn't, you will always learn more if you first try to solve whatever problem exists first, and then if your solution doesn't work or you feel unsure about it, then you could post the proposed solution and any questions you have about it.

Best of luck.

Last edited by Fubarable; 07-11-2009 at 05:51 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-11-2009, 05:50 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default
i have a bet to solve this wit my friend....
plz help....
i m sure he s doin da same in some other forum...
i have less time..
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-11-2009, 05:51 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default
it java................
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-11-2009, 05:57 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
I have an idea of a potential problem (not to mention that Singleton patterns should not be used in general), but again, I await your thoughts on what you think the problem is.

Also, please avoid using unnecessary abbreviations here. For many of our posters English is not a first or second language, and unusual abbreviations or SMS speak may be non-translatable for them.

Again, best of luck
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-11-2009, 06:02 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default
i am not very good in java but my idea of a singleton is singleton pattern is a design pattern that is used to restrict instantiation of a class to one object.
i believe that there is a problem in _instance.
i m not sure...
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-11-2009, 06:06 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
So what happens if the instance is null and one tries to obtain the Singleton object from two different threads at the same time?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-11-2009, 06:11 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default
i ges the return_instance statement must be outside the function
public static Singleton Instance..
n please genuinely help..
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-11-2009, 06:15 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
Quote:
n please genuinely help..
What do you mean here? My post above gives you the problem. And again, please avoid unnecessary abbreviations for reasons noted above.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-11-2009, 06:28 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
unagie is on a distinguished road
Default
okay sorry...
please please help... m in a hurry.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-11-2009, 10:10 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
Also, Google can help. It brought me this link which basically corroborates what I posted above: Introducing the singleton - "The Single Java Object"
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone help me to solve this problem... Vinny Java Announcements 1 07-08-2009 07:59 PM
Plz solve this.... theone3nu Java 2D 3 01-08-2009 06:01 PM
Plz solve this.... theone3nu New To Java 9 12-23-2008 10:42 AM
Solve my Problem kyo New To Java 1 12-16-2008 03:22 PM
Help me to solve problem mansoorhacker New To Java 3 11-13-2008 09:15 AM


All times are GMT +2. The time now is 03:10 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org