Singleton & Multithreading in Java

Posted by vivek jagtap on Stack Overflow See other posts from Stack Overflow or by vivek jagtap
Published on 2012-06-17T14:59:37Z Indexed on 2012/06/17 15:16 UTC
Read the original article Hit count: 177

What is the preferred way to work with Singleton class in multithreaded environment?

Suppose if I have 3 thread, and all they try to access getInstance() method of singleton class at the same time -

  1. What would happen if no synchronization is maintained?
  2. Is it good practice to use synchronized getInstance() method or use synchronized block inside getInstance().

Please advise if there is any other way out.

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading