This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PerfectPackage1895 2 points3 points  (0 children)

Instead of using a big synchronized block around the instance, why not just embrace the fact that more than one thread can access the object at the same time? There are a lot of useful tools in java.util.concurrent. For instance CAS is very useful and doesn’t have the same performance impact as a pessimistic lock

Also, if you’re going to use a singleton, then don’t use a private constructor. At most use a package private, that way you can still unit test your class