Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • I wouldn't say that synchronization is totally unneeded. If the singleton provides access to a shared resource, then some synchronization must take place. I agree that you don't have to synchronize everything, though. Commented Feb 12, 2011 at 17:01
  • @Sergey - I agree, what I am trying to expose is that “if in multithreading environment” as the question states; then simply the usage synchronization in some cases will not be the best. Certainly you can do that if the instantiation isn’t causing substantial overhead in the application. But if it does you might want to decrease this performance impact by using other options like either moving to an eagerly created instance or “double-check locking” to reduce the use of synchronization. Commented Feb 12, 2011 at 18:48
  • unfortunately, DCL is completely broken in Java. Commented Feb 12, 2011 at 18:55
  • @Sergey - If you use a JVM other than Java 5 consider other methods (other than DCL) to implement Singleton. Head First Design Patterns. Item 5: Dealing with multithreading. Here is a thread that shows how to implement DCL in Java 5 or higher How to solve DCL in java taken from Effective Java, Second Edition which is basically the purpose of DCL Commented Feb 12, 2011 at 19:33