It is common that a lot of asynchronies transport library often offers two types of interfaces, returning Future or taking a callback parameter.
An effective to explain the differences between the two would be push vs pull. Future is pull. When you make the asynchronies call, you get a future handle, via it, you can wait on the result. Callback is more like push, the callback method is being passed and executed on the callee side, which often add the results to a queue for further processing.
In Java, Future uses a blocking lock to control the state of Future, when async call is pending for result, the lock is blocked on get call, when data is returned, the lock will be released.
Here is a link to a well written article about Future vs. Callback:
http://www.drdobbs.com/go-parallel/article/showArticle.jhtml?articleID=226700179
No comments:
Post a Comment