Skip to content

Document how to configure the ApplicationEventMulticaster used by the ApplicationContext #29996

Closed
@YJFinBJ

Description

@YJFinBJ

initApplicationEventMulticaster() in AbstractApplicationContext creates a new SimpleApplicationEventMulticaster instance and registers it in the container, but the Executor in it is always null because there is no autowiring for it.

Code as below:

public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {
ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));
Executor executor = getTaskExecutor();
for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
if (executor != null) {
executor.execute(() -> invokeListener(listener, event));
}
else {
invokeListener(listener, event);
}
}
}

So, when it runs it always steps into the else clause. I would like to ask if I want to invoke listener async, must I use @Async

Although @Async can work because of dynamic proxy technique.

Or, must I manually set an async Executor in the SimpleApplicationEventMulticaster instance?

I feel puzzled for the code above.

Best Regards

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions