Results 1 to 1 of 1

Thread: Publishing events to a different multicaster?

  1. #1
    Join Date
    Aug 2012
    Posts
    1

    Default Publishing events to a different multicaster?

    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!

    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>
    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.

    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:

    Code:
    appContext.getBean("applicationEventMulticaster").asInstanceOf[SimpleApplicationEventMulticaster].setTaskExecutor(queueExecutor)
    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?
    Last edited by HerroRygar; Aug 15th, 2012 at 05:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •