public class AsyncCallRunnableListenerHelper extends RunnableListenerHelper
RunnableListenerHelper. In this implementation when listeners are invoked with the
RunnableListenerHelper.callListeners()function, the invocation of all the listeners will occur on the
Executorthat was provided at construction. If the listener was added without a provided executor it will then run on the provided executor (in the thread doing the
RunnableListenerHelper.callListeners()invocation, AKA it will run that listener before executing other listeners). If the listener was added with a provided executor, that listener will still execute on the provided executor (so not necessarily the executor provided at construction time).
If it is desired that all listeners are executed asynchronously from each other, you should
actually use the normal
RunnableListenerHelper, and instead just ensure that an
executor is provided when each listener is added. If you want listeners to execute
concurrently from each other, but not concurrently for any single listener,
DefaultExecutorRunnableListenerHelper is likely a better choice. This class is only
designed to ensure that
RunnableListenerHelper.callListeners() invocations will never block.
To better clarify when this implementation makes sense compared to
DefaultExecutorRunnableListenerHelper. If you have
a LOT of quick running listeners, this is the right class for you. If you have few listeners
that execute quickly, then the normal
RunnableListenerHelper is likely a better choice.
If you have long running/complex listeners,
possibly the better choice. Alternative for the last condition you could use the normal
RunnableListenerHelper, and just ensure that an executor is provided for every listener
(but if you want to ensure a given listener is not executed concurrently the
DefaultExecutorRunnableListenerHelper will handle this for you).
|Constructor and Description|
Constructs a new
addListener, addListener, addListener, callListeners, clearListeners, getSubscribedListeners, registeredListenerCount, removeListener
public AsyncCallRunnableListenerHelper(boolean callListenersOnce, java.util.concurrent.Executor executor)
AsyncCallRunnableListenerHelper. This can call listeners one time, or every time callListeners is called.
trueif listeners should only be called once
RunnableListenerHelper.callListeners()should execute on