Announcement Announcement Module
Collapse
No announcement yet.
ThrowsAdvice and threading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ThrowsAdvice and threading

    I use a DefaultPointcutAdvisor to intercept ThrowsAdvice on a list of beans using a BeanNameAutoProxyCreator.

    This works perfect except on one bean which starts a Runnable class in a thread. When those threads throw exceptions they are not caught by the ThrowsAdvice. Is this the expected behavior? Can you not catch these exceptions because they are in separate threads?

    thanks

  • #2
    This is expected behaviour. ThrowsAdvice does something like wrapping a method in a try-catch block. When you do asynchronous call (new Thread), its like call and forget for the caller. The method called in a new thread can outlive the caller method, so there is no way to catch an exception when the advised caller method is already completed when the exception is raised.
    If you want to do an asynchronous call that does not outlive the caller method, use AsyncTaskExecutor that returns a Future instance. By calling get() on Future in the caller method, an exception raised in an asynchronous method will be rethrown as ExecutionException and intercepted by a ThrowsAdvice.

    Comment

    Working...
    X