[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 = 
            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 = 

    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(

        if (servletContext == null) {
            return null;
        this.cachedApplicationContext = 
            (org.springframework.context.ApplicationContext) servletContext
        return cachedApplicationContext;

Bean 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 {

    public WorkResponse execute(final WorkRequest workRequest) {

        long start = System.currentTimeMillis();
        WorkExchange exchange = new WorkExchange();
        // 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

Start a new discussion in EJB3 at Community

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