V
- The result type returned by the future.public interface ListenableFuture<V>
extends java.util.concurrent.Future<V>
Future that allows asynchronous notifications.
This kind of future can be used to be notified when the result is available, thus removing the need for a blocking thread that waits on the result.
Modifier and Type | Method and Description |
---|---|
boolean |
addCompletionListener(FutureCompletionListener<? super V> listener)
Registers a completion listener with this future.
|
ListenerLockPolicy |
getListenerLockPolicy()
Returns the listener lock-policy used by this future.
|
boolean |
removeCompletionListener(FutureCompletionListener<? super V> listener)
Removes the registration of a completion listener with this future.
|
boolean addCompletionListener(FutureCompletionListener<? super V> listener)
Registers a completion listener with this future. This listener is
notified when the future completes (Future.isDone()
returns
true
). If the future completes before the listener is
registered, the listener is notified immediately while being added.
If the specified listener is already registered with this future, no
action is taken and this method returns false
.
Important note: Typically, the listener is executed by
the thread that sets the future's value. For this reason, it is important
that the listener does not block or perform any long-running operations.
Instead, the listener should delegate any such operation to a different
thread (e.g. using an Executor
). Any violation of this rule might
result in unexpected or unpredictable behavior. In particular, a blocking
listener might cause a dead-lock, which results in the whole application
being stalled indefinitely.
listener
- listener to be registered with this future.true
if the listener has been added,
false
if it has already been added earlier.ListenerLockPolicy getListenerLockPolicy()
removeCompletionListener(FutureCompletionListener)
method when a
listener is removed while a notification of the same listener is in
progress.boolean removeCompletionListener(FutureCompletionListener<? super V> listener)
Removes the registration of a completion listener with this future. The exact behavior of this method depends on the listener lock-policy used by this future.
If the BLOCK
policy is in effect, the
listener is not going to receive a completion notification after this
method returns. If the IGNORE
policy is
in effect, the listener might still be notified after this method
returns. This may only happen if the future completes before this method
returns. If the REPORT
policy is in
effect, this method throws a ConcurrentNotificationException
if
the listener might still be notified. The listener is still removed,
despite the exception being thrown.
If the specified listener is not currently registered with this future,
no action is taken and this method returns false
.
listener
- listener to be unregistered from this future.true
if the listener has been removed,
false
if it has already been removed earlier of if
has never been added.ConcurrentNotificationException
- if the ListenerLockPolicy
is set to REPORT
and the removed listener might still receive a notification
after this method has returned. The listener is still
removed, even if this exception is thrown.getListenerLockPolicy()
Copyright © 2014–2018 aquenos GmbH. All rights reserved.