<!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;">
    Re: Failed to acquire the pool semaphore in empty pool
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/garrydias">Garry Dias</a> in <i>EJB3</i> - <a href="http://community.jboss.org/message/626083#626083">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 Pai... thnx for your reply</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>everything starts in my webservice class MyWorkerWS:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> MyWorkerInterface
<font color="navy">{</font>
&#160;&#160;&#160; <font color="navy"><b>public</b></font> WorkResponse execute(WorkRequest request);
<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 style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
@javax.jws.WebService(portName = "MyWorkerWSPort", name = "MyWorker", serviceName = "MyWorker")
public class MyWorkerWS extends SpringSupport implements MyWorkerInterface {

&#160;&#160;&#160; @javax.jws.WebMethod(operationName = "execute")
&#160;&#160;&#160; @javax.jws.soap.SOAPBinding(parameterStyle = ParameterStyle.BARE)
&#160;&#160;&#160; @javax.jws.WebResult(name = "workResponse", partName = "workResponse", targetNamespace = "http://ws.working.my.com/")
&#160;&#160;&#160; public WorkResponse execute(
&#160;&#160;&#160;&#160;&#160;&#160;&#160; @javax.jws.WebParam(mode = Mode.IN, name = "work", partName = "work") 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkRequest request) 
&#160;&#160;&#160; {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; final int startingDepth = NDC.getDepth();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResponse response = null;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Here I&#180;m looking up my bean via Spring
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyWorkerInterface worker = (MyWorkerInterface) super.getBeanFactory().getBean("myWorkerBean");
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Sometimes it performs around 300ms and sometimes more than 20000ms
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; response = worker.execute(request);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (org.springframework.beans.BeansException beansException) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoggerHelper.error("Application error", beansException);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (EJBException ejbException) {

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final String errorMessage = 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; org.apache.commons.lang.StringUtils.defaultString(ejbException.getMessage());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (errorMessage.startsWith("Failed to acquire the pool semaphore")) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // MyWorkerInterface.execute(WorkRequest) method is delayed for more than 20000ms.
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // When the execute method backs to its normal execution time this EJBException is still happening
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // but the pool seems to be empty
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoggerHelper.error("Pool is full because MyWorkerInterface.execute(WorkRequest) is" +
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "taking more time than normal to perform.", ejbException);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoggerHelper.error("ejb error", ejbException);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; return response;
&#160;&#160;&#160; }
}</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>Spring support class</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
public class SpringSupport {

&#160;&#160;&#160; protected final org.apache.log4j.Logger logger = 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; org.apache.log4j.Logger.getLogger(this.getClass());

&#160;&#160;&#160; @javax.annotation.Resource
&#160;&#160;&#160; private javax.xml.ws.WebServiceContext webServiceContext;
&#160;&#160;&#160; 
&#160;&#160;&#160; private org.springframework.context.ApplicationContext cachedApplicationContext;

&#160;&#160;&#160; protected org.springframework.beans.factory.BeanFactory getBeanFactory() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cachedApplicationContext != null) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return cachedApplicationContext;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (webServiceContext == null) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; javax.xml.ws.handler.MessageContext messageContext = webServiceContext.getMessageContext();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (messageContext == null) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; javax.servlet.ServletContext servletContext = 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (javax.servlet.ServletContext) messageContext.get(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT);

&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (servletContext == null) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.cachedApplicationContext = 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (org.springframework.context.ApplicationContext) servletContext
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .getAttribute(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; return cachedApplicationContext;
&#160;&#160;&#160; }
}</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>Bean class</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
@Clustered
@Local(MyWorkerInterface.class)
@Stateless(name = "MyWorkerBean")
@Interceptors(value = { SpringBeanAutowiringInterceptor.class, LoggingInterceptor.class })
@RolesAllowed(value = "client")
@Pool(value = PoolDefaults.POOL_IMPLEMENTATION_STRICTMAX, maxSize = 30)
public class MyWorkerBean implements MyWorkerInterface {

&#160;&#160;&#160; @RolesAllowed("client")
&#160;&#160;&#160; @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
&#160;&#160;&#160; public WorkResponse execute(final WorkRequest workRequest) {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; long start = System.currentTimeMillis();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkExchange exchange = new WorkExchange();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; exchange.setWorkRequest(workRequest);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; // A JMSProducer is created to send exchange to a JMS queue
&#160;&#160;&#160;&#160;&#160;&#160;&#160; // A MDB class retrieve data from a third party webservice using WorkExchange.workRequest fields
&#160;&#160;&#160;&#160;&#160;&#160;&#160; // A JMSConsumer is created to retrieve exchange object when MDB ends 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoggerUtil.info("Operation time: " + (System.currentTimeMillis() - start));
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; // WorkExchange.workResopnse have been set by MDB
&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResopnse response = exhange.getWorkResponse();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; return response;
&#160;&#160;&#160; }
}</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>Look up settings in Spring xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml">
&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;jee:local-slsb lookup-home-on-startup="false" id="myWorkerBean" business-interface="MyWorkerInterface"
&#160;&#160;&#160;&#160;&#160;&#160;&#160; jndi-name="MyWorkerBean/local" /&gt;</span>
</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><span></span></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/626083#626083">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>