Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Future<V> and Exception

How to ensure that the exception thrown by @Asynchronous method from EJB 3.1 methods are not silently eaten up by Future?
I know one can use Future.get method to retrieve exception but it will wait till the computation is done, a problem in case no exception occur and you have to wait till the computation is over.

(Update)

The scenario is fairly simple. A stateless EJB exposes its method with @Asynchronous annotation, primarily intended for @Local. The AS is JBoss. During computation, its possible that a RuntimeException occurs. Clients may or may not want to poll if the job is finished, but in all cases they should know if exception has occurred. A workaround is possible to use some sort of callback, but I am interested if there is any out of box solution available.

like image 790
anergy Avatar asked Oct 07 '11 15:10

anergy


1 Answers

Did you consider invoking Future#get(timeout, timeUnit) to return the control after the given time if no results are available (the computation is not finished)? You can also invoke Future#isDone() prior to Future#get() to know if the processing is complete.

Either way, you still need to invoke Future#get(-) to get known what has happened and to be sure that the exception is not swallowed.

HTH.

like image 174
Piotr Nowicki Avatar answered Sep 23 '22 02:09

Piotr Nowicki