Spring Async Method Hides Exceptions

I have a strange problem with Async methods. If I run it asynchronously and its job throws a specific exception, it does not display it and just stops execution (no catch, no log).

I found that it works with jasperreport. This is the fault code:

JasperPrint jp1=null; try{ jp1 = JasperFillManager.fillReport(reportD1, params, new JRBeanCollectionDataSource(ingressi)); }catch(Exception e){ log.error(e); e.printStackTrace(); throw e; } 

If this code is inside the annotated Async method, it does not throw an exception and does not register (it just stops execution). If I delete the Async annotation, it produces the following:

 java.lang.ClassNotFoundException: org.apache.commons.collections.map.ReferenceMap 

My problem is not the exception itself, but why does the async method not catch it?

+1
source share
1 answer

Which @Async method @Async accurate? If you use the asynchronous method, you should always support the Future type as the result. If you provide a void method, there is no way to throw any exception that will occur in the (asynchronous) stream.

There is a catch method for the void method. In short: Spring Framework 4.1 allows you to register an exception handler for this kind of thing, check out SPR-8995 . 4.1.RC1 will be available soon if you want to try.

+1
source

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


All Articles