Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Identify the problem within this snippet of Java/C# code implementing Singleton Desig

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Identify the problem within this snippet of Java/C# code implementing Singleton Desig

    Q: 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
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Identify the problem within this snippet of Java/C# code implementing Singleton D

    Do you know what the problem is and are just asking it as a challenge to others, or do you need help figuring out what the issue is?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Identify the problem within this snippet of Java/C# code implementing Singleton D

    i just need a help desperately...
    I have too submit an answer for this but there is no way i am seeing to solve this question......
    plz plz help me out plz

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Identify the problem within this snippet of Java/C# code implementing Singleton D

    Can you explain what the problem is?
    Are there error messages?
    Does the code not work as expected?

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Identify the problem within this snippet of Java/C# code implementing Singleton D

    Hint: Consider what would happen if multiple threads tried to call Instance() at the same time and _instance = null.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Identify the problem within this snippet of Java/C# code implementing Singleton D

    i just need a help desperately...
    I have too submit an answer for this but there is no way i am seeing to solve this question......
    How I interpret this statement: I have to turn in a homework assignment and can't figure out the answer to this question - please do so for me. Not going to happen. Of course, maybe I am misinterpreting your problem, in which case you should restate it.

    That being said, along with helloworld's hint, here's another: inheritance.

Similar Threads

  1. Code snippet pls?
    By srinivas0615 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 30th, 2011, 02:28 AM
  2. API singleton theory
    By dunnkers in forum Java Theory & Questions
    Replies: 10
    Last Post: February 24th, 2011, 12:57 PM
  3. How to identify a roman numeral
    By dunWorry in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 20th, 2010, 12:58 AM
  4. Implementing HTML tags in Java Source Code
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: March 19th, 2010, 09:29 PM
  5. Problem while implementing a basic user interface menu
    By Rastabot in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 3rd, 2009, 04:38 PM