Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring @Async should have some way of specifying UncaughtExceptionHandler [SPR-8995] #13635

Closed
spring-issuemaster opened this Issue Jan 5, 2012 · 8 comments

Comments

Projects
None yet
3 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Jan 5, 2012

Dwayne D'Souza opened SPR-8995 and commented

Currently an exceptions in Async proxied methods fail silently and do not pass to the default UncaughtExceptionHandler. This means you need to wrap every async method with AspectJ in order to achieve unexpected error handling in these methods.

e.g.

@Override
@Async
public void asyncExceptionTest() {
int i=1/0;
}

This will fail silently.


Issue Links:

  • #16706 UncaughtExceptionHandler is not configured with AspectJ
  • #16397 Asynchronous method execution is always invoked before bean validation
  • #13246 Use ErrorHandler in TaskExecutors

19 votes, 20 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 1, 2012

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 20, 2014

Stéphane Nicoll commented

The reason why the UncaughtExceptionHandler is not invoked is because the ExecutorService does not honour that. Specifically, we use ThreadPoolExecutor that has a callback method for that kind of use case: [afterExecute](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html#afterExecute(java.lang.Runnable, java.lang.Throwable))

See also this thread

We intend to provide a dedicated callback handler for asynchronous operations that would provide more context.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Apr 1, 2014

Stéphane Nicoll commented

The current plain is to define a new interface AsyncUncaughtExceptionHandler that can be specified on either task:annotation-driven or AsyncConfigurer.

When an exception is thrown from an asynchronous method invocation and that method has a void return type, the AsyncUncaughtExceptionHandler is invoked with the exception, the method and the method arguments.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Aug 16, 2014

Janning Vygen commented

The solution only works for Proxy but not AspectJ mode in 4.1.0.RC2
See AspectJAsyncConfiguration vs ProxyAsyncConfiguration

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Aug 18, 2014

Stéphane Nicoll commented

Thanks, I have created #16706

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 20, 2016

Mukund Jalan commented

Update may be needed as per #18954

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 20, 2016

Stéphane Nicoll commented

This issue is closed. What update are you talking about?

@winston9527

This comment was marked as off-topic.

Copy link

winston9527 commented Feb 22, 2019

restart server when spring async queue has elements。 queue data will lost , how to resolve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.