Singleton Design
Singleton Design
SHUBHRA MUKHERJEE 1
DESIGN PATTERN : SINGLETON
Logging
Configura on se ngs
Caching
... with single point of control.
SHUBHRA MUKHERJEE 2
DESIGN PATTERN : SINGLETON
Thread-safe
Lazy
Be er performance
SHUBHRA MUKHERJEE 3
DESIGN PATTERN : SINGLETON
Thread-safe
Instance created even if not used
Best approach
Lazy
Thread-safe
No synchroniza on overhead
SHUBHRA MUKHERJEE 4
DESIGN PATTERN : SINGLETON
SHUBHRA MUKHERJEE 5
DESIGN PATTERN : SINGLETON
SHUBHRA MUKHERJEE 6
DESIGN PATTERN : SINGLETON
SHUBHRA MUKHERJEE 7
DESIGN PATTERN : SINGLETON
Not recommended
Singleton = one instance = no parameters
Workaround: configure via method, not constructor
Thread
Strategy Lazy Easy Perf
Safe
Synchronized Lazy
Double-Checked Lock
Bill Pugh
Enum Singleton
SHUBHRA MUKHERJEE 8