eXo Platform 3.5

- Prev
- Next

## Chapter 66. ListenerService

## Asynchronous Event Broadcast

Basicaly, ListenerService used to store Listeners and broadcast events to them.

ListenerService event broadcasting works in next way - it takes a destination listeners and executes event on those listeners.

But, some events may take a lot of time, so idea to make event processing asynchronous is usefull.

> What do I need to make my listener asynchronous?

- It's very simple, just mark your Listener implementation as `@Asynchronous`.

    @Asynchronous

    class AsynchListenerWithException<S,D> extends Listener<S,D>

    {

       @Override

       public void onEvent(Event<S,D> event) throws Exception

       {

          // some expensive operation

       }

    }

Now, our AsynchListener will be executed in separate thread by `ExecutorService`.

By default, `ExecutoreService` configured with thread pool size 1, you can change it in configuration:

       <component>

          <key>org.exoplatform.services.listener.ListenerService</key>

          <type>org.exoplatform.services.listener.ListenerService</type>

          <init-params>

             <value-param>

                <name>asynchPoolSize</name>

                <value>5</value>

             </value-param>

          </init-params>

       </component>

- Prev
- Up
- Home
- Next