2

As far as I know, no two threads can use a stateless session bean at the same time.

In my case, I have two stateless session beans. In the second bean I have an asynchronous method. This method will be called from the first bean.

My doubt is, will the first bean be used by another thread after thread X has called a method on the first bean and returned successfully?

Code below

@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MyBean {
    @EJB(beanName="AsyncBean")
    private AsyncBean asyncBean;
    public String call() {
        // some code here
        asyncBean.call();
        return result;
    }
}

@Stateless(name="asyncBean")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class AsyncBean {
    @Asynchronous
    public void call() {
        // some code which takes some time
    }
}

I want to know if MyBean stateless bean will be used by another thread or not after thread X has returned successfully and the async task is still running.

Thank you.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74

1 Answers1

2

Yes, the EJB container can reuse the MyBean instance as soon as the first call method returns. The EJB container will not wait for the asynchronous call to complete.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90