How to disable passivation for SFSB in WildFly

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.


Recommended Articles

Configure Stateful EJB Caches for WildFly Applications - Latest Version

Learn how to configure stateful EJB caches in WildFly applications. Includes details on cache types and configuration.

Configure HTTP Session Management in WildFly 17 Clustered Applications

Learn how to configure HTTP Session Management in clustered Web applications using WildFly 17, ensuring session survival across server crashes and restarts.

Upgrade WildFly 8.0.0 to 8.1.0 with a Single Patch: A Step-by-Step Guide

Learn how to apply a patch to upgrade your WildFly 8.0.0 application server to the latest 8.1.0 version in this step-by-step tutorial.

Configure a WildFly Resource Adapter and Use It in MDBs - Step-by-Step Guide

Learn how to configure a Resource Adapter in WildFly, including deployment, configuration, and usage with Message Driven Beans (MDB). #WildFly #JavaConnectorArchitecture #MDB #ResourceAdapter