[jboss-user] [EJB3] - Re: Failed to acquire the pool semaphore in empty pool

Garry Dias do-not-reply at jboss.com
Mon Sep 12 12:00:54 EDT 2011


Garry Dias [http://community.jboss.org/people/garrydias] created the discussion

"Re: Failed to acquire the pool semaphore in empty pool"

To view the discussion, visit: http://community.jboss.org/message/626083#626083

--------------------------------------------------------------
Hi Pai... thnx for your reply

everything starts in my webservice class MyWorkerWS:

public interface MyWorkerInterface
{
    public WorkResponse execute(WorkRequest request);
}





@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;
    }
}


Spring support class


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;
    }
}


Bean class


@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;
    }
}


Look up settings in Spring xml


     <jee:local-slsb lookup-home-on-startup="false" id="myWorkerBean" business-interface="MyWorkerInterface"
        jndi-name="MyWorkerBean/local" />
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/626083#626083]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110912/7f52a649/attachment.html 


More information about the jboss-user mailing list