I have a Settable Future object "temp" which has a context set to it. Also temp.addListener(new Runnable{...})
method is called, basically registering a listener to it. However eventually if any exception comes up then temp.setException()
is called. If the setException
is called will the listener be de-registered or will the context be cleared (basically will the Settable Future object be damaged after exception is set)?
The flow of code is something like this :-
temp.setContext({temp.set(//some value is set if everything goes right) || temp.setException(//set exception if something comes up)});
temp.addListener(new Runnable{ run(){temp.get()}})
When you call setException()
, the ListenableFuture
will run its listener . If you want to write code that will not be run in that case, you can use Futures.addCallback
instead of addListener
. ( addCallback
lets you specify code to be run only in case of success or only in case of failure.)
As for what happens with the context: The context isn't part of the ListenableFuture
API. I don't know if it was added by you or another library. You'd have to consult that class to find out how it behaves.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.