IBM


13.4.3 Stateful EJB timeout option

Additionally, you can specify a timeout value for stateful session beans. A bean can time out in the METHOD_READY or in the PASSIVATED state. If you try to access a bean that has timed out, you see an exception similar to that in Example 13-5.

Example 13-5 Stateful EJB timed out exception

com.ibm.ejs.container.SessionBeanTimeoutException: Stateful bean StatefulBeanO(BeanId(Webbank#webbankEJBs.jar#Transfer, ebf64d846a), state = METHOD_READY) timed out.

Session beans that have timed out can be removed by the container, for example, if it needs to free memory. However, a well-written application should not rely on beans to time out to free memory. Instead, it is important that the developer explicitly calls remove() on a bean when this stateful bean is not needed anymore.

The default timeout is 600 seconds. You can set the timeout integer value as a parameter of a stateful session bean by opening the EJB deployment descriptor and selecting the Bean tab, as in Figure 13-17. By specifying a value of 0, you set the bean to never expire.

Setting this timeout inserts the following property in the ejbExtensions tag of the IBM bindings file:

<ejbExtensions xmi:type="ejbext:SessionExtension"
  xmi:id="Session_1_Ext" timeout="120">

If a bean times out in the METHOD_READY state and is consequently removed by the container, the ejbRemove() method is called on the bean instance. If a bean times out in the passivated state, ejbRemove() is not called, according to the EJB specification.


Redbooks ibm.com/redbooks

Next