简体   繁体   中英

ApplicationEventMulticaster UncaughtExceptionHandler

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;
    }

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);


}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM