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 -
- What would happen if no synchronization is maintained?
- Is it good practice to use synchronized
getInstance()
method or use synchronized block insidegetInstance()
.
Please advise if there is any other way out.
© Stack Overflow or respective owner