Future <V> and Exception
How can I ensure that the exception thrown by the @Asynchronous method from EJB 3.1 methods is not silently eaten by Future?
I know that you can use the Future.get method to catch an exception, but it will wait until the calculation is completed, the problem is if an exception is not raised, and you need to wait until the calculation finishes.
(Update)
The script is pretty simple. Unmatched agents provide their method with @Asynchronous annotation, primarily for @Local. AS - JBoss. During the calculation, a RuntimeException is possible. Customers may or may not want to question if the work is completed, but in all cases they need to know if an exception has occurred. A workaround is to use some kind of callback, but I'm wondering if there is an available solution.
Do you consider calling Future # get (timeout, timeUnit) to return the control after a specified time, if the results are not available (calculation is not completed)? You can also call Future # isDone () before the future # get () to see if processing is complete.
In any case, you still need to call Future # get (-) to find out what happened and make sure that the exception is not swallowed.
NTN.
There is a solution to your problem. The countdownlatch method is implemented to notify the calling thread of how many future tasks will be completed. here is an example of the hot use of countdownlatch. Therefore, implement a small synchronous class and add an instance to all called objects at the time of submission. which will work as a callback.
If you have access to the configuration of your EJB container, and you can install the artist, you can add Guall addCallback . This method requires com.google.common.util.concurrent.ListenableFuture
instead of the usual one. You will get such a future by setting the instance executor of your instance to ListeningExecutorService
. Guava provides a factory method to decorate each ExecutorService as a ListeningExecutorService, so you can use everything you had before. ExecutionService.