Skip to content

dulajra/all-about-singletons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

all-about-singletons

This repository demonstrates all main patterns which can be used to create singletons in Java. A more detailed explanation can be found at http://blog.dulaj.info/2017/07/java-singletons-using-enum-type-best.html.

Singleton patterns implemented

  • Singleton with public static final field
  • Singleton with static factory method
  • Singleton with lazy initialization and fine grained synchronization
  • Singleton with enum

Problems with singletons demostrated here

  • Serialize and Deserialize problem
  • Problem with private constructor when using reflection

License

All the source code has been licensed under MIT License and free to use for any kind of work.