Skip to content

Latest commit

 

History

History
8 lines (6 loc) · 606 Bytes

NonThreadSafeSingleton.md

File metadata and controls

8 lines (6 loc) · 606 Bytes

NonThreadSafeSingleton

Category: pmd
Rule Key: pmd:NonThreadSafeSingleton

⚠️ This rule is deprecated in favour of S2444.


Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possible by instantiating the object directly. Static singletons are usually not needed as only a single instance exists anyway. Other possible fixes are to synchronize the entire method or to use an initialize-on-demand holder class (do not use the double-check idiom). See Effective Java, item 48.