Skip to content

Commit 690b4b8

Browse files
committed
docs: add comparison table for singleton implementations
1 parent 47a97fb commit 690b4b8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

singleton/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ Sequence diagram
3737

3838
![Singleton Pattern sequence diagram](./etc/singleton-sequence-diagram.png)
3939

40+
## Singleton Implementation Comparison (for eager and lazy initialization)
41+
42+
| Feature | Eager Initialization | Thread-Safe Lazy Initialization |
43+
|----------|----------|----------|
44+
| Object Creation | During class loading | First call to `getInstance()` |
45+
| Thread Safe | Yes | Yes |
46+
| Synchronization Required | No | Yes |
47+
| Memory Usage | Higher | Lower |
48+
| Performance | Faster access | Slight synchronization overhead |
49+
| Complexity | Simple | Moderate |
50+
4051
## Programmatic Example of Singleton Pattern in Java
4152

4253
Joshua Bloch, Effective Java 2nd Edition p.18

0 commit comments

Comments
 (0)