Asynchronous Mdb vs EJB 3.1 Method

When should I choose the ejb async method over MDB using the Java messaging service to run async long-term tasks?

+6
source share
2 answers

@Asynchronous is only suitable if an external transaction needs to start several parts of the work in parallel, and then wait for them all (or start one part of the work in the background, do some work in the foreground, and then wait in the background). @Asynchronous not suitable for transactional "fire and forgetting" because the container may fall before the asynchronous operation starts to execute (in my opinion, void EJB arithmetic methods are very rarely useful, perhaps for something like updating the cache in memory) , If you want to guarantee that the work will be performed asynchronously, without waiting for its completion, then you must send a message to MDB or schedule an EJB timer.

+6
source

@MessageDriven (MDB) is part of the JMS API. JMS has all sorts of additional features when it comes to retrying when message consumption fails, transaction support, and also allows you to control the message queue.

@Asynchronous annotation was not introduced without java-ee-6 (ejb 3.1).

Assuming usecase is a simple asynchronous call in a java-ee-6 container or higher, use @Asynchronous ( arun guptas blog about this )

If you need more, then JMS may be an option.

+1
source

Source: https://habr.com/ru/post/978417/


All Articles