Hot Posts

Chapter 4: Singleton Pattern

In this chapter we will examine the different ways that a developer can implement the singleton design pattern, its common usage and pitfalls. We start by using static members and methods and demonstrate the problems this causes in multi-threaded environments.

We will see the advances that were made in Java SE 5 with the introduction of the enum type and how it can be used to create thread safe singletons. Then we will discuss the use of the @Singleton annotation in Java EE and how this has radically changed the way we implement the singleton pattern in session beans.

We will introduce the use of BEAN and CONTAINER managed concurrency and we will see how the use of the @LockType annotation controls access to business methods. We finish the chapter with a discussion of the main issues that have dogged the singleton pattern and why it is considered an anti-pattern and has fallen out of favour.

Professional Java EE Design Patterns

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: