Results 1 to 2 of 2

Thread: ThrowsAdvice and threading

  1. #1

    Default 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. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •