How to use Enum as Singleton in Java with Example

Tutorials Shared by the Internet Community

Advertisements


Synopsis

From Java 5 onwards there is a new way to implement Singleton design pattern, by using Enum. Enum has some distinct benefits in terms of thread-safety

Statistics

  • Total Hits - 27008

  • Total Votes - 114 votes

  • Vote Up - 51 votes

  • Vote Down - 63 votes

  • Domain - javarevisited.blogspot.com

  • Category - JAVA/Getting Started

  • Submitted By - Javin Paul

  • Submitted on - 2012-11-01 15:37:10

Description

From Java 5 onwards there is a new way to implement Singleton design pattern, by using Enum. Enum has some distinct benefits in terms of thread-safety during instance creation, serialization guarantee by JVM and amazingly reduce amount of code which makes it perfect choice of using as Singleton class. ...


Site  |   Broken  |   Tweet  |   Facebook  |     |   Save  |   Liked  |   Down

Advertisements