JbossTimeoutSettingForSeam

Version 8

    Aligning Timeout Values for HTTP Session and JBoss Default SFSB

     

    (Work in Progress)

     

    Goal

    The aim of this document is to describe the changes that are necessary to align HTTP and SFSB timeout values between a Seam application and its JBoss runtime environment.  In the Seam forums there have been many cases where "Could not destroy component" exceptions are thrown during destruction phase of a stateful session bean.  One of the causes of these exceptions is down to the timeout values of HTTP and SFSB being different.  (TODO: improve explanation)

     

    A typical exception would look like this:

     

    2006-11-30 02:52:03,664 WARN  [org.jboss.seam.contexts.Contexts] Could not destroy component: OrderSession
    javax.ejb.EJBNoSuchObjectException: Could not find Stateful bean: 41z4l26-wb41k6-ev4j007b-1-ev4jirql-bw
            at org.jboss.ejb3.cache.simple.SimpleStatefulCache.get(SimpleStatefulCache.java:268)
            at org.jboss.ejb3.stateful.StatefulRemoveInterceptor.removeSession(StatefulRemoveInterceptor.java:127)
            at org.jboss.ejb3.stateful.StatefulRemoveInterceptor.invoke(StatefulRemoveInterceptor.java:87)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
            at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:131)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
            at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
            at $Proxy219.destroy(Unknown Source)
            at x.x.OrderSession$$FastClassByCGLIB$$e5185c52.invoke(<generated>)
            at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
            at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
            at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:69)
            at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
            at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39
    )

     

    HTTP Session Timeout

     

    To set the HTTP timeout value, locate the following file within your application's war archive and either edit or add the following session-timeout value to your needs.  This example uses 15 minutes.  If no session-timeout value was specified, then the default timeout value is 30 minutes.

     

    File:

    WEB-INF/web.xml

     

    <session-config>
      <session-timeout>15</session-timeout>
    </session-config>     

     

     

    Note: Value is in minutes;

     

    SFSB Timeout

     

    You have 2 choices here:

     

    1. you can set the SFSB timeout on a per class basis using the @CacheConfig annotation; or

    2. you can set the default SFSB value for your JBoss environment that will apply to all session beans.

     

    Using the @CacheConfig annotation, you may set the session timeout for a stateful session bean as follows:

     

    @Name("myAccount")
    @Stateful
    @Scope(ScopeType.SESSION)
    
    @CacheConfig(idleTimeoutSeconds=900)
    public class MyAccountBean implements MyAccount, Serializable
    {
      ...
    }
    

     

    Note. Value is in seconds: 900 seconds = 15 minutes as specified in the HTTP timeout - set this to your needs; This must be done for each session bean in your application.

     

     

    Setting the default SFSB timeout requires two JBoss configuration files to be set:

     

    Please note that setting the config in this way is required for every server that the Seam code is deployed to and applies to all EJB3 applications on that server.

     

    File 1:

    JBOSS_HOME/server/default/deploy/ejb3-interceptors-aop.xml

     

    Find entry matching '

    <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">

    ':

     

    <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
    
       <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
          ...
          <!-- Align this value with session timeout in web.xml -->
          <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class @org.jboss.annotation.ejb.Clustered)">
             @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=900)
          </annotation>

     

     

    If you are using EJB2, you will need to set the Set the idleTimeoutSeconds value in the standardjboss.xml file.  Please note that if you are using EJB3, you DO NOT need to change the standardjboss.xml file

     

     

    File 2:

    JBOSS_HOME\server\default\conf\standardjboss.xml

     

    Find entry for '

    <container-name>Standard Stateful SessionBean</container-name>

    ':

     

        <container-configuration>
          <container-name>Standard Stateful SessionBean</container-name>
          ...
          <container-cache-conf>
            ...
            <cache-policy-conf>
              
    <remover-period>900</remover-period>
              <max-bean-life>900</max-bean-life>
    
    ...

     

     

     

    Note. Values are in seconds: 900 seconds = 15 minutes as specified in the HTTP timeout - set this to your needs;

     

     

    As a final note, this example sets HTTP and SFSB values to be exactly the same. It is sometimes recommended that the SFSB timeouts are set to be longer than the HTTP session timeout.  (TODO: clarify this)

     

    That is all. Aligning these timeout values will help prevent those "Could not destroy component: XXXX" exceptions in some cases.  Please be aware that there are other causes of this exception too such as the serialisability of the SFSB.  Please refer to the JBoss Seam forum if you are still getting the timeout errors.

     

    Further information and discussion, see references.

     

     

    References:

     

    1. Original Discussion Topic     http://www.jboss.com/index.html?module=bb&op=viewtopic&t=93589

    2. How do the timeouts work with EJB3 Stateful Beans