Singleton Session EJB: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 25: Line 25:
Once instantiated according to the previous sequence, the Singleton bean instance lives for the duration of the application.
Once instantiated according to the previous sequence, the Singleton bean instance lives for the duration of the application.


===Shutdown===
===Destruction===


When the application is shutting down, the container invokes [[EJB_Annotations#.40javax.annotation.PreDestroy|@PreDestroy]]  methods, and this ends the life of the instance.
When the application is shutting down, the container invokes [[EJB_Annotations#.40javax.annotation.PreDestroy|@PreDestroy]]  methods, and this ends the life of the instance.
 
Note that during destruction, the container ensures that all Singleton beans on which this instance [[@javax.ejb.DependsOn|@DependsOn]] are still available during the instance's @PreDestroy methods.


==Dependencies between Singletons==
==Dependencies between Singletons==

Revision as of 19:09, 27 April 2017

Internal

Concepts

Overview

A singleton session bean is a component that is instantiated once per application. For distributed applications that span multiple VMs, each application will have on singleton session bean instance per JVM. The instances are intended to be shard, and must support concurrent access. The Singleton bean instances maintain state between invocations, but the state is not required to survive container shutdown or crash.

Lifecycle

Instantiation

The singletons are lazy instantiated by default. The container instantiates them when the first invocation arrives. However, a Singleton bean can declare that it needs eager initialization, when the application starts, by declaring the @Startup annotation. If eagerly initialized, it is the container's responsibility to initialize the bean before any external client requests are delivered to the instance.

To create the instance, the container invokes newInstance() method on the Singleton bean class. Then the container performs any dependency injection. Then the container calls @PostConstruct methods.

Dependencies

A Singleton bean may declare an initialization dependency on another Singleton bean instance, by declaring the @DependsOn annotations. More details on dependencies available in @DependsOn.

Active Life

Once instantiated according to the previous sequence, the Singleton bean instance lives for the duration of the application.

Destruction

When the application is shutting down, the container invokes @PreDestroy methods, and this ends the life of the instance.

Note that during destruction, the container ensures that all Singleton beans on which this instance @DependsOn are still available during the instance's @PreDestroy methods.

Dependencies between Singletons

Transactional Behavior

Concurrency

Also see

EJB Concepts - Concurrency

Interceptors

Restrictions

Singleton beans must not implement javax.ejb.SessionSychronization interface or use the session synchronization annotations.