When should I choose ejb async method over MDB with java message service in order to fire async long time tasks?
@Asynchronous
is only appropriate if the outer transaction needs to launch several pieces of work in parallel and then wait on them all (or launch a single piece of work in the background, do some work in the foreground, and then wait on the background work). @Asynchronous
is not appropriate for transactional "fire and forget" because the container might crash before the asynchronous work ever begins executing (in my opinion, void EJB asynchronous methods are very rarely useful, perhaps for something like updating an in-memory cache). If you want to guarantee work will happen asynchronously without waiting for it to complete, then you should send a message to an MDB or schedule an EJB timer.
@MessageDriven
(MDBs) is part of JMS API. JMS has all sorts of extras when it comes to retrying on failed message consumption,transaction support and also allows you to control the queue of messages.
@Asynchronous
annotation was not introduced unti java-ee-6 (ejb 3.1).
Assuming the usecase is simple asynchronous invocation in a java-ee-6 container or above, use @Asynchronous (arun guptas blog on this)
If you need more beyond that, JMS might be an option
© 2022 - 2024 — McMap. All rights reserved.