Skip to content

Commit 4337d84

Browse files
committed
Remove spring.event.invoke-listener startup event
Prior to this commit, the `SimpleApplicationEventMulticaster` would be instrumented with the `ApplicationStartup` and start/stop events for invoking event listeners (`spring.event.invoke-listener`). This feature was already limited to single-threaded event publishers, but is still flawed since several types of events can happen concurrently. Due to the single-threaded nature of the startup sequence, our implementation should not produce startup events concurrently. This can cause issues like gh-26057, where concurrent events lead to inconcistencies when tracking parent/child relationships. This commit removes the `spring.event.invoke-listener` startup event as a result. Fixes gh-26057
1 parent 8f0ad73 commit 4337d84

File tree

3 files changed

+1
-38
lines changed

3 files changed

+1
-38
lines changed

spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.springframework.context.ApplicationEvent;
2626
import org.springframework.context.ApplicationListener;
2727
import org.springframework.core.ResolvableType;
28-
import org.springframework.core.metrics.ApplicationStartup;
29-
import org.springframework.core.metrics.StartupStep;
3028
import org.springframework.lang.Nullable;
3129
import org.springframework.util.ErrorHandler;
3230

@@ -57,9 +55,6 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
5755
@Nullable
5856
private ErrorHandler errorHandler;
5957

60-
@Nullable
61-
private ApplicationStartup applicationStartup;
62-
6358

6459
/**
6560
* Create a new SimpleApplicationEventMulticaster.
@@ -127,22 +122,6 @@ protected ErrorHandler getErrorHandler() {
127122
return this.errorHandler;
128123
}
129124

130-
/**
131-
* Set the {@link ApplicationStartup} to track event listener invocations during startup.
132-
* @since 5.3
133-
*/
134-
public void setApplicationStartup(@Nullable ApplicationStartup applicationStartup) {
135-
this.applicationStartup = applicationStartup;
136-
}
137-
138-
/**
139-
* Return the current application startup for this multicaster.
140-
*/
141-
@Nullable
142-
public ApplicationStartup getApplicationStartup() {
143-
return this.applicationStartup;
144-
}
145-
146125
@Override
147126
public void multicastEvent(ApplicationEvent event) {
148127
multicastEvent(event, resolveDefaultEventType(event));
@@ -156,16 +135,6 @@ public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableTyp
156135
if (executor != null) {
157136
executor.execute(() -> invokeListener(listener, event));
158137
}
159-
else if (this.applicationStartup != null) {
160-
StartupStep invocationStep = this.applicationStartup.start("spring.event.invoke-listener");
161-
invokeListener(listener, event);
162-
invocationStep.tag("event", event::toString);
163-
if (eventType != null) {
164-
invocationStep.tag("eventType", eventType::toString);
165-
}
166-
invocationStep.tag("listener", listener::toString);
167-
invocationStep.end();
168-
}
169138
else {
170139
invokeListener(listener, event);
171140
}

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,7 @@ protected void initApplicationEventMulticaster() {
815815
}
816816
}
817817
else {
818-
SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
819-
simpleApplicationEventMulticaster.setApplicationStartup(getApplicationStartup());
820-
this.applicationEventMulticaster = simpleApplicationEventMulticaster;
818+
this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
821819
beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
822820
if (logger.isTraceEnabled()) {
823821
logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +

src/docs/asciidoc/core/core-appendix.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,4 @@ its behavior changes.
16691669
| `spring.context.refresh`
16701670
| Application context refresh phase.
16711671
|
1672-
1673-
| `spring.event.invoke-listener`
1674-
| Invocation of event listeners, if done in the main thread.
1675-
| `event` the current application event, `eventType` its type and `listener` the listener processing this event.
16761672
|===

0 commit comments

Comments
 (0)