春天异步方法隐藏例外 [英] Spring Async method hides exceptions

查看:106
本文介绍了春天异步方法隐藏例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有异步方法一个奇怪的问题。
如果我在异步方式运行它,它的工作引发了一些特殊的例外,它不显示它,只是停止执行(没有赶上,没有日志)。

I have a strange issue with Async methods. If I run it in async way and its job throws some particular exception, it doesn't show it and simply stop the execution (no catch, no log).

我发现它与jasperreport的工作。
这是断块code:

I found it working with jasperreport. This is the fault block code:

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

如果这个code是一个异步注解的方法不会抛出异常,不记录里(只是停止执行)。
如果我删除了异步注释,它抛出这样的:

If this code is inside an Async annotated method it doesn't throw the exception and doesn't log (simply stops the execution). If I remove the Async annotation, it throws this:

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

我的问题是不是例外本身,而是为什么异步方法不抓住它?

My trouble is not the exception itself, but why async method doesn't catch it?

推荐答案

哪种方法 @Async 到底是什么?如果您运行的是异步方法,你应该总是垂青一个未来的结果类型。如果你提供了一个无效的方法,有没有办法来传​​输任何类型的异常的(异步)的线程会发生的。

Which method is @Async exactly? If you are running an asynchronous method you should always favour a Futureas result type. If you provide a void method, there's no way to transmit any sort of exception that would happen in the (asynchronous) thread.

有是渔获无效的方法。长话短说:Spring框架4.1允许你注册一个异常处理程序之类的东西,检查 SPR- 8995 。 4.1.RC1将很快上市,如果你想尝试。

There is catch for void method. Long story short: Spring Framework 4.1 allows you to register an exception handler for that kind of things, check SPR-8995. 4.1.RC1 will be available shortly if you want to try.

这篇关于春天异步方法隐藏例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆