As for any Java EE compatible application server, Oracle Weblogic ships with an EJB container that maintains a pool of stateless session beans to avoid creating and destroying instances. As for the Stateful counterpart, Oracle WLS creates SFSBs instances as they are needed to service client requests. Between requests, these instances reside in a bean-specific cache in the active state, ready for the next request. Both types of EJB endpoints can be configured through an Oracle WSL custom deployment descriptor named weblogic-ejb-jar.xml that is used to override or enhance the configuration provided by the standard ejb-jar.xml file. Next section will show how to do it:
Configuring Oracle Weblogic Stateless EJB pool
The stateless pool configuration is composed of two parameters: a lower and an upper bound.
- The upper bound is specified by the max-beans-in-free-pool parameter. It should be set equal to the number of threads expected to invoke the EJB concurrently. Using a too small value will impact concurrency.
- The lower bound is specified by the initial-beans-in-free-pool parameter. Increasing the value of initial-beans-in-free-pool increases as well the startup time for the server. The advantage is that the cost of creating EJB instances is not incurred at run time.
Both elements can be defined as part of the weblogic-ejb-jar.xml within a “pool” stanza:
<weblogic-enterprise-bean> <ejb-name>MessageExporterSessionEJB</ejb-name> <stateless-session-descriptor> <pool> <max-beans-in-free-pool>10</max-beans-in-free-pool> <initial-beans-in-free-pool>10</initial-beans-in-free-pool> </pool> . . . . </weblogic-enterprise-bean>
Configuring Oracle Weblogic Stateful EJB cache
The size of the SFSB cache, is on the other hand, defined by the max-beans-in-cache element in the weblogic-ejb-jar.xml deployment descriptor file. The default value is 1000. Here’s a sample configuration which limits this value to 200 units:
<weblogic-enterprise-bean> <ejb-name>AccountBean</ejb-name> <stateful-session-descriptor> <stateful-session-cache> <max-beans-in-cache>200</max-beans-in-cache> <idle-timeout-seconds>1200</idle-timeout-seconds> </stateful-session-cache> </stateful-session-descriptor> </weblogic-enterprise-bean>
You should set this value to the expected number of concurrent stateful EJB clients in order to avoid excessive bean passivation and activation. Consider that setting this value too high will consume memory unnecessarily.