Results 1 to 11 of 11
  1. #1
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    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;
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    snippet of Java/C# code
    ? which is this supposed to be, Java or C#? They are similar but not one and the same.

    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.

  3. #3
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    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..

  4. #4
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    it java................

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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

  6. #6
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    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...

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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?

  8. #8
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    i ges the return_instance statement must be outside the function
    public static Singleton Instance..
    n please genuinely help..

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  10. #10
    unagie is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    okay sorry...
    please please help... m in a hurry.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, Google can help. It brought me this link which basically corroborates what I posted above: Introducing the singleton - "The Single Java Object"

Similar Threads

  1. Could someone help me to solve this problem...
    By Vinny in forum Java Software
    Replies: 1
    Last Post: 07-08-2009, 07:59 PM
  2. Plz solve this....
    By theone3nu in forum Java 2D
    Replies: 3
    Last Post: 01-08-2009, 06:01 PM
  3. Plz solve this....
    By theone3nu in forum New To Java
    Replies: 9
    Last Post: 12-23-2008, 10:42 AM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 03:22 PM
  5. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •