When a Stateful Bean is experiencing a period of inactivity, the EJB container may
decide to remove it from memory temporarily. This process is called passivation. Most of the
state of the EJB is saved automatically except for transient fields. When the EJB is restored,
the stateless EJB has its original content except for the transient fields.
Passivation is a resource consuming task therefore you can configure WildFly / JBoss EAP 7 to disable passivation.
There are two ways to disable passivations of Stateful Session Beans with WildFly / JBoss EAP 7:
Disabling Passivation programmatically
Including an EJB 3.2 attribute named βpassivationCapableβ in your SFSB definition as follows:
@Stateful(passivationCapable=false) public class AccountEJB { . . . }
Disabling passivation at configuration level
Change the stateful cache-ref
from distributable
to simple
.
The CLI command to run is:
/subsystem=ejb3:write-attribute(name=default-sfsb-cache,value=simple)
That will reflect in the following change in configuration:
<stateful default-access-timeout="5000" cache-ref="simple" passivation-disabled-cache-ref="simple"/>
Please note that, by disabling passivation, all EJB instances are held on memory without passivation.
Therefore they will consume memory until they are expired by @javax.ejb.StatefulTimeout
or removing an instance by calling remove API annotated @javax.ejb.Remove
when finishing the SFSB execution.