0

I'm using Spring's ApplicationEventMulticaster.

How do I configure the uncaught error handling when listening to events?

    public ApplicationEventMulticaster asyncApplicationEventMulticaster() {
        SimpleApplicationEventMulticaster eventMulticaster = new 
        SimpleApplicationEventMulticaster(); 
        eventMulticaster.setTaskExecutor(getAsyncExecutor());
        return eventMulticaster;
    }
DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

0

Wrap the executor:

public class LoggingExecutor implements Executor {
private static final Logger logger = LoggerFactory.getLogger(LoggingExecutor.class);
private Executor executor;

public LoggingExecutor(Executor executor) {
    this.executor = executor;
}

@Override
public void execute(Runnable task) {
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            try {
                task.run();
            } catch (Exception e) {
                logger.error("Uncaught exception", e);
                throw e;
            }
        }
    };
    executor.execute(task);


}}
DD.
  • 21,498
  • 52
  • 157
  • 246