spring-framework / org.springframework.context.event / SimpleApplicationEventMulticaster

SimpleApplicationEventMulticaster

open class SimpleApplicationEventMulticaster : AbstractApplicationEventMulticaster

Simple implementation of the ApplicationEventMulticaster interface.

Multicasts all events to all registered listeners, leaving it up to the listeners to ignore events that they are not interested in. Listeners will usually perform corresponding instanceof checks on the passed-in event object.

By default, all listeners are invoked in the calling thread. This allows the danger of a rogue listener blocking the entire application, but adds minimal overhead. Specify an alternative task executor to have listeners executed in different threads, for example from a thread pool.

Author
Rod Johnson

Author
Juergen Hoeller

Author
Stephane Nicoll

See Also
#setTaskExecutor

Constructors

<init>

SimpleApplicationEventMulticaster()

Create a new SimpleApplicationEventMulticaster.

SimpleApplicationEventMulticaster(beanFactory: BeanFactory)

Create a new SimpleApplicationEventMulticaster for the given BeanFactory.

Functions

multicastEvent

open fun multicastEvent(event: ApplicationEvent): Unit
open fun multicastEvent(event: ApplicationEvent, eventType: ResolvableType): Unit

setErrorHandler

open fun setErrorHandler(errorHandler: ErrorHandler): Unit

Set the ErrorHandler to invoke in case an exception is thrown from a listener.

Default is none, with a listener exception stopping the current multicast and getting propagated to the publisher of the current event. If a task executor is specified, each individual listener exception will get propagated to the executor but won't necessarily stop execution of other listeners.

Consider setting an ErrorHandler implementation that catches and logs exceptions (a la org.springframework.scheduling.support.TaskUtils#LOG_AND_SUPPRESS_ERROR_HANDLER) or an implementation that logs exceptions while nevertheless propagating them (e.g. org.springframework.scheduling.support.TaskUtils#LOG_AND_PROPAGATE_ERROR_HANDLER).

setTaskExecutor

open fun setTaskExecutor(taskExecutor: Executor): Unit

Set a custom executor (typically a org.springframework.core.task.TaskExecutor) to invoke each listener with.

Default is equivalent to org.springframework.core.task.SyncTaskExecutor, executing all listeners synchronously in the calling thread.

Consider specifying an asynchronous task executor here to not block the caller until all listeners have been executed. However, note that asynchronous execution will not participate in the caller's thread context (class loader, transaction association) unless the TaskExecutor explicitly supports this.