First page Back Continue Last page Graphics
Passivation / Activation
The container may passivate idle bean instances
- Reduces number of objects to save memory
- Instance is reactivated when needed again
These actions trigger two bean methods:
- Container calls them just before passivation / after activation
How is a bean passivated?
- Stateless session beans: never passivated
- Stateful session beans: serialized to disk
- Entity beans: returned to pool
- Details follow…
Notes:
As an EJB server operates it will create dozens, even hundreds, of enterprise beans. At any given moment, most of those beans may be idle. To conserve memory, the container can passivate (deactivate) an idle bean. When a client needs that bean again, the container can activate it.
Both the SessionBean and EntityBean interfaces have two methods to react to these container actions: ejbPassivate( ) is called just before passivation, and ejbActivate( ), just after activation.
How the container actually passivates a bean instance depends on the type of bean. Stateless session beans are never passivated; they’re always ready in the pool. The container passivates stateful session beans by serializing them to disk and allowing them to be garbage collected. And entity beans are simply removed from use and put back into the ready pool.