<!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="https://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;">
    Asynchronous EJB calls dropped with StrictMaxPool
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/david_b">david_b</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/763780#763780">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have an interesting problem with dropped asynchronous EJB calls on AS 6.0.0.Final.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We recently encountered the issue where Stateless Session Beans are not cleaned up. We implemented the recommended work around and moved from ThreadLocalPool to StrictMaxPool, with a StrictMaxPool size of 50. This has resolved the memory leak, however it's introduced a new problem.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Our application periodically scans a directory and calls a Stateless processing bean for all the files present. The method on the processing bean is @Asynchronous, so it returns immediately, and there can be 1000s of files in the directory when the scan occurs. Under these conditions all 50 instances of the processing bean will be utilised and subsequent calls queued until an instance becomes available. It appears that the queue size is only 500, after which calls to the processing bean are dropped.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have written two simple beans to illustrate the problem - a Singleton bean with a scheduled method and a Stateless Session Bean with an asynchronous method. The scheduled bean calls the asynchronous method 1000 times, of which ~550 calls succeed, with the remaining ~450 dropped.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The Singleton scheduled bean:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">@Singleton
@Startup
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> ScheduledBean
<font color="navy">{</font>
&#160;&#160;&#160; Logger logger = Logger.getLogger(ScheduledBean.class);
&#160;&#160;&#160; 
&#160;&#160;&#160; @EJB(lookup=<font color="red">"ProcessingBean/local"</font>)
&#160;&#160;&#160; ProcessingBeanInterface processingBean;
&#160;&#160;&#160; 
&#160;&#160;&#160; @Schedule(second=<font color="red">"0"</font>, minute=<font color="red">"*"</font>, hour=<font color="red">"*"</font>, persistent=<font color="navy"><b>false</b></font>)
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> run()
&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font>(<font color="navy"><b>int</b></font> i = 0; i &lt; 1000; ++i)
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.info(<font color="red">"Running processing bean, id: "</font> + i);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; processingBean.doWork(i);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The Stateless processing bean:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">@Stateless
@Local(ProcessingBeanInterface.class)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> ProcessingBean <font color="navy"><b>implements</b></font> ProcessingBeanInterface
<font color="navy">{</font>
&#160;&#160;&#160; Logger logger = Logger.getLogger(ProcessingBean.class);
&#160;&#160;&#160; 
&#160;&#160;&#160; @Asynchronous
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> doWork(<font color="navy"><b>int</b></font> id)
&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.info(<font color="red">"Doing work, id: "</font> + id);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Thread.sleep(1000);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>catch</b></font> (InterruptedException e)
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</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>Is this queue size configurable, or can we configure the AS to not drop EJB calls?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If it's not possible to configure the queue for this type of usage then I'll look at modifying our scheduled bean to initiate the processing in batches.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any help or insight would be greatly appreciated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks,</p><p>Dave</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/763780#763780">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://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>