<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    How do the timeouts work with EJB3 Stateful Beans
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/admin">Administrator Administrator</a> in <i>EJB3</i> - <a href="http://community.jboss.org/docs/DOC-9628">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><h2><span>EJB3 Timeouts with Stateful Session Beans</span></h2><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h3><span>When using stateful session beans, you can control the timeouts for.</span></h3><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li type="ol"><p>How long the bean(with the state) remains in memory.&#160; State can be passivated to disk(or cache) to free up memory for other beans or processes.</p></li><li type="ol"><p>How long the bean remains active before it is completely removed.&#160; This controls the life span of the SFSB.</p></li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h3><span>There are two timeouts that control this:</span></h3><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li type="ol"><p><span style="font-family: 'courier new', courier;">idleTimeoutSeconds</span> - the number of seconds that a SFSB remains active but unused until the state is passivated.</p></li><li type="ol"><p><span style="font-family: 'courier new', courier;">removalTimeoutSeconds</span> - this represents the end of the beans life, the bean and state are deleted when this timeout is hit but the bean was unused. 0 represents infinity. When <span style="font-family: 'courier new', courier;">removalTimeoutSeconds &lt;= idleTimeoutSecond</span>, then the bean is not passivated, it is just straightforwardly removed.</p></li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h3><span>You can change this in two places.&#160; </span></h3><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h4><span>1.&#160; You can change the timeouts per bean by defining a class annotation.</span></h4><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>For a clustered configuration specify a simple CacheConfig with your specific timeouts.&#160; Remember that 0 is infinite.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>If you are NOT in a clustered app server..</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: 'courier new', courier;">@CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>If you are IN a clustered app server..</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: 'courier new', courier;">@CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h4><span>2.&#160; You can change these globally if you go to the deploy/ejb3-interceptors-aop.xml file.</span></h4><p>You will see the following defined for clustered and non clustered SFSBs.&#160; Just edit the file and replace the timouts that you would like.&#160; Make sure that you change the correct one if you are clustered or non-clustered.&#160; You may want to change both for constancy.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">&#160;&#160; &lt;annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)"&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
&#160;&#160;&#160;&#160;&#160; &lt;/annotation&gt;

&#160;&#160;&#160;&#160;&#160; &lt;!-- Clustered cache configuration --&gt;
&#160;&#160;&#160;&#160;&#160; &lt;annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND class(@org.jboss.annotation.ejb.Clustered)"&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
&#160;&#160;&#160;&#160;&#160; &lt;/annotation&gt;
&#160;&#160;&#160;&#160;&#160; &lt;annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)"&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
&#160;&#160;&#160;&#160;&#160; &lt;/annotation&gt;</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Warning:</strong>Be careful what you set the removalTimeoutSeconds to.&#160; If you are in the middle of a session and bean is not touched, it's possible that you could end up in a condition where you are depending on the state, you haven't touched it in the given timeout and the state is suddenly gone.&#160; You will get the following errror...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: 'courier new', courier;">javax.ejb.EJBNoSuchObjectException: Could not find Stateful bean: 41z4l26-wb41k6-ev4j007b-1-ev4jirql-bw</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ref:</p><p>(1.) timout setting for seam.&#160; JbossTimeoutSettingForSeam</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-9628">going to Community</a></p>

        <p style="margin: 0;">Create a new document in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>