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-projects-issues opened this issue Jan 5, 2012 · 8 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

19 votes, 20 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 1, 2012

Gareth Smith commented

Somebody has posted a workaround here: http://stackoverflow.com/questions/8735870/spring-async-uncaught-exception-handler

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 18, 2014

Stéphane Nicoll commented

Thanks, I have created #16706

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 20, 2016

Mukund Jalan commented

Update may be needed as per #18954

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 20, 2016

Stéphane Nicoll commented

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

@winston9527

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants