Tuesday, April 04, 2006

Singletons and EJB

This post contains the points to be noted when implementing Singleton Pattern in the EJB tier. As described in the previous post (EJB Programming Restrictions), the EJB programming model imposes some restrictions on the application programmer.
  • The restriction of not using read/write static variables within the EJB tier implies that the static variables have to be defined as final.
  • The other main implication of using Singletons in the EJB tier is when the EJBs are used in a clustered architecture. In such cases, is server in the cluster will have an instance of the singleton object.
The article "When is a singleton not singleton" describes a list of situations when a singleton may have multiple instances. This is a concise list:
  • Multiple singletons in two or more virtual machines
  • Multiple singletons simultaneously loaded by different class loaders
  • Multiple singletons arising when someone has subclassed your singleton
  • Copies of a singleton object that has undergone serialization and deserialization
  • Multiple instances created due to incorrect factory implementation.
Related posts

No comments:

Post a Comment

Popular Posts