Saturday, June 11, 2022

Design Patterns - Singleton


  • Eager - thread safe but can be broken with below techniques
    • reflection
    • object cloning
    • serialization/deserialization
  • Lazy - in multithread environment can be archived with below techniques
    • synchronize whole method
    • Double checked locking - synchronize inside method + volatile
    • Bill Pugh method - static Holder Class
    • Enum method

Referances

Singleton all scenarios : link  

Baeldung : link 

No comments:

Post a Comment

Thank you for your comment!