<!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;">
    Re: Failed to acquire the pool semaphore in empty pool
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/garrydias">Garry Dias</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/760376#760376">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Yes. I&#180;m still writing a post with a sequence diagram to explain better.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To be short:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>At the line where I worte <code class="jive-code jive-java"><span style="color: darkgreen;">// A JMSConsumer is created to retrieve exchange object when MDB end </span></code>there&#180;s lot of statements and one of that is a call to javax.jms.MessageConsumer.receive() method. However, when the producer sent the message it set a Time To Live in my jms message. This TTL was 20 seconds. As my MDB connect to a third party webService that hangs more than 30 seconds sometimes, my jms message died before MDB acks the comsumption. Meanwhile, the javax.jms.MessageConsumer.receive() method is waiting for a message that should never come because the jms message relies in DLQ now. So, javax.jms.MessageConsumer.receive() method will wait forever and an available <code class="jive-code jive-java">MyWorkerBean </code>instance in my pool (annotated as <code class="jive-code jive-java">@Pool(value = PoolDefaults.POOL_IMPLEMENTATION_STRICTMAX, maxSize = 30)</code>) will be decreased. You can see this decreasing in jmx-console, menu j2ee.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The solution was set a TTL for MessageConsumer.receive() method. So today my code looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><code class="jive-code jive-java">@Clustered<br/>@Local(MyWorkerInterface.class)<br/>@Stateless(name = <span style="color: red;">"MyWorkerBean"</span>)<br/>@Interceptors(value = <span style="color: navy;">{</span> SpringBeanAutowiringInterceptor.class, LoggingInterceptor.class <span style="color: navy;">}</span>)<br/>@RolesAllowed(value = <span style="color: red;">"client"</span>)<br/>@Pool(value = PoolDefaults.POOL_IMPLEMENTATION_STRICTMAX, maxSize = 30)<br/><span style="color: navy;"><strong>public</strong></span> <span style="color: navy;"><strong>class</strong></span> MyWorkerBean <span style="color: navy;"><strong>implements</strong></span> MyWorkerInterface <span style="color: navy;">{</span><br/> <br/>&#160;&#160;&#160; @RolesAllowed(<span style="color: red;">"client"</span>)<br/>&#160;&#160;&#160; @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)<br/>&#160;&#160;&#160; <span style="color: navy;"><strong>public</strong></span> WorkResponse execute(<span style="color: navy;"><strong>final</strong></span> WorkRequest workRequest) <span style="color: navy;">{</span><br/> <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: navy;"><strong>long</strong></span> start = System.currentTimeMillis();<br/> <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkExchange exchange = <span style="color: navy;"><strong>new</strong></span> WorkExchange();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; exchange.setWorkRequest(workRequest);<br/> <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: darkgreen;">// A JMSProducer is created to send exchange to a JMS queue</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: darkgreen;">// A MDB class retrieve data from a third party webservice (expensive operation taking between 300 to 60000ms to finish) using WorkExchange.workRequest fields</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ...</code></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <code class="jive-code jive-java">ObjectMessage responseMessage</code> = (<code class="jive-code jive-java">ObjectMessage</code>) <code class="jive-code jive-java">messageConsumer.receive(20000);</code> </p><p><code class="jive-code jive-java">&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... </code></p><p><code class="jive-code jive-java"><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoggerUtil.info(<span style="color: red;">"Operation time: "</span> + (System.currentTimeMillis() - start));<br/> <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: darkgreen;">// WorkExchange.workResponse have been set by MDB</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResponse response = exhange.getWorkResponse();<br/> <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: navy;"><strong>return</strong></span> response;<br/>&#160;&#160;&#160; <span style="color: navy;">}</span><br/><span style="color: navy;">}</span></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="color: navy;">[]s<br/></span></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/760376#760376">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>