DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Avatar

Davide Lorenzo Marino

Software Factory Manager at The Innovation Factory srl

Rome, IT

Joined Nov 2015

http://stackoverflow.com/users/1803853/davide-lorenzo-marino

Stats

Reputation: 198
Pageviews: 246.6K
Articles: 3
Comments: 5
  • Articles
  • Comments

Articles

article thumbnail
How to Use the Executor Framework
A tutorial to using the Executor framework in Java to decouple command submissions from command execution.
January 8, 2016
· 164,216 Views · 31 Likes
article thumbnail
Immutable Objects in Java
An overview plus some practical tips on immutable objects in Java.
December 18, 2015
· 69,230 Views · 18 Likes
article thumbnail
Another Singleton Implementation
How to implement the Singleton pattern in Java in five different ways.
December 10, 2015
· 13,104 Views · 9 Likes

Comments

Another Singleton Implementation

Dec 12, 2015 · Davide Lorenzo Marino

The singleton pattern is a design pattern that restricts the instantiation of a class to one object.

In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction.

Both definitions are taken from wikipedia.

So why you said that this is not a singleton, but a pojo? I don't understand.

Another Singleton Implementation

Dec 11, 2015 · Davide Lorenzo Marino

There are context in wich you need to know how to build a singleton:

- when the customer like to have to total control of the code

- because introducing a framework is not compatible with performance aspects

- because somebody will ask you how to create a singleton in a job interview

- you are creating a framework and you need to expose singletons

- for personal curiosity

Another Singleton Implementation

Dec 10, 2015 · Davide Lorenzo Marino

Thanks for the reference to the JLS specifications

Another Singleton Implementation

Dec 10, 2015 · Davide Lorenzo Marino

In most situations the eager implementation is the best one. Also the enum solution proposed by Ondrej is a good one. But the eager one will be loaded always also when is not used only because you import the class. The process of class loading will create the singleton instance also if never used. All the lazy implementations will be loaded only on demand.

Another Singleton Implementation

Dec 10, 2015 · Davide Lorenzo Marino

Yes enum is another possibility from java 1.5 because the instantiation is thread safe.

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: