Run listener/send task locally as fallback on RejectedExecutionException
Closes gh-32171
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.context.event;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -143,7 +144,13 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
||||
Executor executor = getTaskExecutor();
|
||||
for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
|
||||
if (executor != null && listener.supportsAsyncExecution()) {
|
||||
executor.execute(() -> invokeListener(listener, event));
|
||||
try {
|
||||
executor.execute(() -> invokeListener(listener, event));
|
||||
}
|
||||
catch (RejectedExecutionException ex) {
|
||||
// Probably on shutdown -> invoke listener locally instead
|
||||
invokeListener(listener, event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
invokeListener(listener, event);
|
||||
|
||||
Reference in New Issue
Block a user