Creating a singleton bean
We will use a singleton to support a game application. A
PlayerBean will be created to support the attributes of a player. We will assume that our game will never have more than one player so a singleton is an appropriate choice for this type of bean.
The process of creating a singleton bean uses two steps:
- Use the @Singleton annotation to designate the bean as a singleton
- Add appropriate methods to the class
These methods will reflect the functionality desired for the singleton.
How to do it...
Begin this recipe by creating a Java EE application called
SingletonExample. Within the EJB module, create a package called
packt and add the singleton
PlayerBean. In the WAR module, create a
servlet package and add a