Results 1 to 2 of 2
  1. #1
    userj2ee is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default Singleton Thread safe class

    Hi,

    Can anyone tell me how to make a Singleton thread safe class without the use of Synchronized method or block? This is one question which is asked in all the interviews i face.

    Thanks for the help

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by userj2ee View Post
    Hi,

    Can anyone tell me how to make a Singleton thread safe class without the use of Synchronized method or block? This is one question which is asked in all the interviews i face.

    Thanks for the help
    A class is loaded amd initialized in a thread safe way, so this'll do:

    Java Code:
    public class Singleton {
       private static Singleton instance= new Singleton();
       public Singleton getInstance() { return instance; }
       ...
    }
    kind regards,

    Jos

Similar Threads

  1. Thread safe without using synchronization
    By swetu.vc in forum Threads and Synchronization
    Replies: 3
    Last Post: 01-20-2010, 08:06 AM
  2. Thread Safe Methods / Locks
    By mrhyman in forum Threads and Synchronization
    Replies: 16
    Last Post: 10-24-2008, 09:57 PM
  3. Replies: 2
    Last Post: 10-06-2008, 09:06 PM
  4. The safe way to stop a thread
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:31 PM
  5. Struts framework. Is this thread safe?
    By JavaAl2 in forum Web Frameworks
    Replies: 1
    Last Post: 01-17-2008, 03:01 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
  •