<!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;">
    release ThreadlocalPool resources?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/robert.geisler">Robert Geisler</a> in <i>EJB3</i> - <a href="http://community.jboss.org/message/589030#589030">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>hello community...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i have got some questions concerning invoking and pooling of Stateless Session Beans (SLSB).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>we use JBoss 4.2.2 default configuration, EJB3 SLSBs are pooled by ThreadlocalPool (deploy/ejb3-interceptors-aop.xml). we noticed from JMX Console that the SLSB pools blow up in the long run, meaning that a lot of SLSB objects are kept in heap space. we investigated this behaviour and it seems that thread creation may be the root case of the problem.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>our client uses Remote Method Invocation (RMI) through the DefaultEjb3Connector (JBoss Remoting Connector, deploy\ejb3.deployer\META-INF\jboss-service.xml). the Remoting Connector installs an AcceptorThread. whenever a client does invoke a Remote Business Interface method a SocketServerInvoker routes the client invocation from this AcceptorThread to a WorkerThread (ServerThread) that actually handles the request.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>in case multiple clients invoke methods concurrent, multiple WorkerThreads are created from AcceptorThread, thus we got t running WorkerThreads on the server (where t corresponds to the maximum of concurrent client invocations at a single moment). it seems that these WorkerThreads stay alive after invocation response and get used by next client invocations.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>now a client invocation triggers some business logic to be performed on the server. this process involves b SLSBs (starts from client with remote invocation and uses several local invocations between EJBs!). for each SLSB there is a pool (ThreadlocalPool as mentioned before). the ThreadlocalPool creates new instances of our EJBs for every WorkerThread on the server (see StatelessInstanceInterceptor.invoke) and always keeps one of these instances (see ThreadlocalPool.release). as the result there are (t * b) bean instances that will never be destroyed until server shutdown (note: it is possible to stop SLSB pool, destroying all the bean instances (InfinitePool.destroy), but we dont want to manually start/ stop these pools during runtime!).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>we think this is a strange behaviour! just imagine 100 clients invoke some business functionality at the same time. that creates 100 WorkerThreads. assumming that the business logic involves 5 different EJBs there will be 100 * 5 = 500 objects (bean instances) in the heap space. and these objects will never be released/ destroyed!?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>maybe i just did not find it... so let me simply ask for it:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li>is there a mechanism that removes (killes or finishes) WorkerThreads after responding to the client?<br/>or are these threads supposed to stay alive forever?<ol></ol></li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>in addition we deploy a MessageDrivenBean (MDB) on the server and register it to a Queue. the MDB is a single instance MDB (configured through ActivationConfigProperty maxSession=1). the clients may send messages to this Queue to inform the server about some status and the MDB will process these messages one by one.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>when a message is received the onMessage method of our MDB is invoked in so called WorkManager thread (PooledInvoker invokes JmsServerSession.run which invokes onMessage on the MDB). the onMessage again involves several EJBs (local invocations!) and therefor instances of these EJBs are create from ThreadlocalPool. after a message is processed the WorkManager thread finishes, thus dies. but after the thread died the bean instances created by the ThreadlocalPool are kept in InfinitePool.active. that means if JBoss is running some days without restart and the MDB receives more and more messages (processed by newly created threads), the pool blows up, because ThreadlocalPool does not destroy the bean instances ever. is this the way it is supposed to be?? or</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li>is there a mechanism that removes bean instances from ThreadlocalPool (respectively from InfinitePool.active) after the corresponding thread died??</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i read some documentation in WIKI and the forums. there was mentioned another Pool implementation: StrictMaxPool. StrictMaxPool does not create bean instances per thread, but creates instances on demand, restricted by a maximum pool size. for MDBs the StrictMaxPool is configured as default in ejb3-interceptors-aop.xml, but for SessionBeans it is ThreadlocalPool.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li>why are there different default pool configurations for Session and MessageDrivenBeans?</li><li>what are the advantages and disadvantages of ThreadlocalPool and StrictMaxPool (performance??)?<br/>are there general guide lines that explain when to use ThreadlocalPool or StrictMaxPool?</li><li>could StrictMaxPool solve the problems that ThreadlocalPool causes in the situations described above?<br/>StrictMaxPool should not keep bean instances, but release them after response -independent of which thread created and used the bean, shouldnt it?</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i am confused by the different mechanism to Remote Method Invocations and incovations through Java Messaging are handled... i would be glad if someone could explain these differences to, especially in case of the SLSB pools, threading and client invocations.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>thanks in advance</p><p>robert</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/589030#589030">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>