I'd like to have events be handled in a separate thread than the caller. Per the documentation on SimpleApplicationEventMulticaster, you just need to replace the TaskExecutor with a different one, such as a thread-pool based one. No problem!
The problem is that this new SimpleApplicationEventMulticaster isn't used by the application - it still uses whatever one it was previously using, according to the log files.Code:<bean id="queueExecutor" class="java.util.concurrent.ScheduledThreadPoolExecutor" destroy-method="shutdownNow"> <constructor-arg type="int" value="${queueExecutor.corePoolSize}" /> </bean> <bean id="applicationEventMulticaster" class="org.springframework.context.event.SimpleApplicationEventMulticaster"> <property name="taskExecutor" ref="queueExecutor" /> </bean>
How do I make this new one the default?
EDIT: I verified that threading is not working the way I expect it to. In the event publisher, I log to the console the name of the current thread. In the event subscriber, I also log the name of the current thread. In every case, they are the same.
EDIT 2: As a hacky test, I wrote the following code that will manually set the task executor property:
Doing this, the app behaves as I want it to. Handlers operate in a different thread (in a totally separate pool) from the caller. Why does this work if I programmatically set it, but not if declared via XML?Code:appContext.getBean("applicationEventMulticaster").asInstanceOf[SimpleApplicationEventMulticaster].setTaskExecutor(queueExecutor)


Reply With Quote