I am a beginner in Java concurrent library and learning to use ListenableFuture in my code. I went through this document and still confused about which one is the preferred way of registering runnable code to my ListenableFuture object:
future.addListener(Runnable, Executor) vs Futures.addCallback(ListenableFuture<V>, FutureCallback<V>, Executor)
It will be really helpful if someone can throw light on performance, use-cases, and which one to prefer over others!
the difference is that for addListener you supply Runnable, and for addCallback you sipply FutureCallback. Runnable is not provided with the result, so if you need it, you have to make additional efforts.
In short, if you want to use future's result, use addCallback, otherwise use addListener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With