1

I have a Stateless EJB method(ejbMethod1) that needs to call a web service operation(wsOper1), if this call fails It needs to call another web service operation(wsOper2).

My problem is: I don't need the returning of wsOper2 to return from ejbMethod1! I want to delegate this work to another piece of my application and return immediately.

Option1:: My first approach to this problem was to use a global LinkedBlockingQueue for storing an Object representing the wsOper2 I needed to do, and have N threads retrieving elements from this queue and executing the call.

Option2:: Create a Runnable and delegate to some global thread pool. There is one that I can use?

Or is another option that I'm not contemplating?

... PS: Im using Glassfish 4.1 & JRE8 and I'm new to the Java EE world :P


UPDATED:

I used a ManagedExecutorService to execute wsOper2 asynchronously as a Runnable.

@Resource
private ManagedExecutorService executor;

Thanks Ryan :)

nms
  • 325
  • 1
  • 14

1 Answers1

1

From the EJB spec:

The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread, or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.

See Adam's Blog for more information on EJBs and threading.

Ryan
  • 2,058
  • 1
  • 15
  • 29
  • Great! If this correctly answers your question, can you accept it by clicking the checkmark on the left of the answer? Thanks. – Ryan Apr 20 '15 at 14:32