What states does a stateful session bean go through, including passivation and activation?
The stateful session bean lifecycle has four states: Does Not Exist, Ready, Passive, and being removed. Passivation and activation are unique to stateful beans for memory management.
- Bean instance does not exist in memory
- Client calls create() on home interface
- Container creates instance, calls setSessionContext(), calls ejbCreate()
- Bean enters Ready state, dedicated to this client
- Client calls business methods on the bean
- Bean retains conversational state for this client
- Container invokes ejbPassivate() callback
- Bean serializes its state to storage
- Bean instance removed from memory
- Triggered when container reaches instance limit
- Client calls method on passivated bean
- Container deserializes state, creates/reuses instance
- Container invokes ejbActivate() callback
- Bean returns to Ready state
- Client calls remove() OR client times out
- Container calls ejbRemove()
- Bean destroyed, data removed from database
- Supports passivation/activation for memory efficiency
- No instance pooling (dedicated to one client)
- ejbCreate() can accept client-specific parameters
- Built from: Stateful Session Bean
- Related: Passivation, Activation, ejbPassivate(), ejbActivate()
- Don’t rely on ejbRemove() or ejbPassivate() for critical cleanup
- External resources (DB connections) should be released in passivate and re-acquired in activate