<!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;"> </p><p>everything starts in my webservice class MyWorkerWS:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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>
    <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;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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 {
    @javax.jws.WebMethod(operationName = "execute")
    @javax.jws.soap.SOAPBinding(parameterStyle = ParameterStyle.BARE)
    @javax.jws.WebResult(name = "workResponse", partName = "workResponse", targetNamespace = "http://ws.working.my.com/")
    public WorkResponse execute(
        @javax.jws.WebParam(mode = Mode.IN, name = "work", partName = "work")
        WorkRequest request)
    {
        final int startingDepth = NDC.getDepth();
        WorkResponse response = null;
        try {
            //Here I´m looking up my bean via Spring
            MyWorkerInterface worker = (MyWorkerInterface) super.getBeanFactory().getBean("myWorkerBean");
           
            //Sometimes it performs around 300ms and sometimes more than 20000ms
            response = worker.execute(request);           
        } catch (org.springframework.beans.BeansException beansException) {
            LoggerHelper.error("Application error", beansException);
        } catch (EJBException ejbException) {
            final String errorMessage =
                org.apache.commons.lang.StringUtils.defaultString(ejbException.getMessage());
               
            if (errorMessage.startsWith("Failed to acquire the pool semaphore")) {
                // MyWorkerInterface.execute(WorkRequest) method is delayed for more than 20000ms.
                // When the execute method backs to its normal execution time this EJBException is still happening
                // but the pool seems to be empty
                LoggerHelper.error("Pool is full because MyWorkerInterface.execute(WorkRequest) is" +
                        "taking more time than normal to perform.", ejbException);
            }
            else {
                LoggerHelper.error("ejb error", ejbException);
            }
        }
        return response;
    }
}</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Spring support class</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">
public class SpringSupport {
    protected final org.apache.log4j.Logger logger =
        org.apache.log4j.Logger.getLogger(this.getClass());
    @javax.annotation.Resource
    private javax.xml.ws.WebServiceContext webServiceContext;
   
    private org.springframework.context.ApplicationContext cachedApplicationContext;
    protected org.springframework.beans.factory.BeanFactory getBeanFactory() {
        if (cachedApplicationContext != null) {
            return cachedApplicationContext;
        }
        if (webServiceContext == null) {
            return null;
        }
        javax.xml.ws.handler.MessageContext messageContext = webServiceContext.getMessageContext();
        if (messageContext == null) {
            return null;
        }
        javax.servlet.ServletContext servletContext =
            (javax.servlet.ServletContext) messageContext.get(
                    javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT);
        if (servletContext == null) {
            return null;
        }
        this.cachedApplicationContext =
            (org.springframework.context.ApplicationContext) servletContext
            .getAttribute(
                    org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        return cachedApplicationContext;
    }
}</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Bean class</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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 {
    @RolesAllowed("client")
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public WorkResponse execute(final WorkRequest workRequest) {
        long start = System.currentTimeMillis();
       
        WorkExchange exchange = new WorkExchange();
        exchange.setWorkRequest(workRequest);
       
        // A JMSProducer is created to send exchange to a JMS queue
        // A MDB class retrieve data from a third party webservice using WorkExchange.workRequest fields
        // A JMSConsumer is created to retrieve exchange object when MDB ends
       
        LoggerUtil.info("Operation time: " + (System.currentTimeMillis() - start));
       
        // WorkExchange.workResopnse have been set by MDB
        WorkResopnse response = exhange.getWorkResponse();
       
        return response;
    }
}</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Look up settings in Spring xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml">
     <span class="jive-xml-tag"><jee:local-slsb lookup-home-on-startup="false" id="myWorkerBean" business-interface="MyWorkerInterface"
        jndi-name="MyWorkerBean/local" /></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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>