There’s obviously more to the bean’s lifecycle than just creation and business methods...

What about when a client wants to remove a bean? What about activation and passivation of stateful session beans? And what really does happen when a bean is created? What makes bean creation different from plain old object construction?

In this chapter, we’ll look at all the stages of a session bean’s life, for both stateful and stateless session beans.

The bean lifecycle (special moments in a bean’s life)

Stateful session beans

  • Bean creation (when the client wants a bean)

  • Bean use (when the client calls a business method)

  • Bean passivation (the bean is put to sleep to conserve resources)

  • Bean activation (the bean wakes up to service a business method from the client)

  • Bean removal (when the client is finished with the bean, or the bean times out)

Stateless session beans

  • Bean creation (when the container wants to make a bean)

  • Bean use (when the client calls a business method)

  • Bean removal (when the container decides there are too many beans in the pool)

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.