Sunday, March 23, 2014

EJB 3.1 Stateless Session Bean lifecycle

The SLSB (StateLess Session Bean) has a lifecycle with only 2 phases, the "Does Not Exist" and the "Method-Ready Pool" phase, because it does not preserve conversational state, which is the big characteristic of this EJB.

SLSB Lifecycle
SLSB Lifecycle, from book "Oreilly Enterprise Javabean 3.1, 6th Edition"

Life-cycle Events
@PostConstruct
@PreDestroy

When going from the "Does Not Exist" to the "Method-Ready Pool", the no-argument constructor is called by the contained; next the container proceeds with code injection where applicable and the calls the method that is annotated with the @PostConstruct annotation. It is not mandatory the presence of this method, but if it exists, then it can be called with a what-so ever name, but it need to be void, have no arguments and must not throw checked exceptions.

In the "Method-Ready Pool", the bean is ready to attend the execution of the business methods.

When the container decides to destroy the bean, the bean goes back to the "Does not Exist" state and the method annotated with @PreDestroy is called, if it exists. Like the @PostConstruct method, it follows the same rules: can have anyname, needs to be void, have no arguments and must not throw checked exceptions.

No comments:

Post a Comment