Basically I have the problem of a long running task in my web application. Currently this task is executed by an EJB which is blocking for the time it is executing the task (task is an external programm and the EJB just waits for the result).
Now according to this post, I thought of using a Message Driven Bean together with a JMS Queue.
My Question: What are the advantages of this approach? If I'd annotate the calling method of the EJB as @Asychnronous
wouldn't I have the same features like with a MDB? Is the feature that pending jobs won't be lost the only advantage of the JMS/MDB approach? In terms of resource management is it better to let an EJB wait for the result of the task or a MDB?
I have used JMS for this pattern a lot, and the reason is that before EJB 3.1, it was simply not possible to make asynchronous calls to Session Beans. That's why you are likely to find such code quite often in existing apps.
Using asynchronous calls on EJBs has the benefit to be easier to setup (using JMS is not that complicated, but you need to create the resources, etc.). Using JMS has a couple of benefits if you are running in an environment where availability and scalability are important topics: