What happens to a stateless session bean from creation to destruction?
The stateless session bean lifecycle has three states: Does Not Exist, Method-Ready Pool, and being removed. The container manages all transitions.
- Bean instance does not exist in memory
- Container calls Class.newInstance() to create instance
- Container calls setSessionContext() to associate bean with container
- Container calls ejbCreate() to initialize bean
- Bean enters the “Method-Ready Pool” of equivalent instances
- Container can call any business method
- Any instance can serve any client
- Each method call may be handled by a different instance
- Container calls ejbRemove() when bean is destroyed
- Bean returns to Does Not Exist state
- ejbRemove() is a cleanup method—release resources
- No passivation/activation (stateless has no state to serialize)
- All instances in pool are equivalent
- Container controls creation and destruction
- ejbCreate() takes no parameters (no client-specific init data)
- Built from: Stateless Session Bean
- Related: Instance Pooling, ejbCreate(), ejbRemove()
- Don’t rely on ejbRemove()—it may never be called if container crashes
- Stateless beans can be pre-created at startup (not lazily created)