Difference between CompletableFuture, Future and RxJava's Observable

前端 未结 4 1920
礼貌的吻别
礼貌的吻别 2020-12-12 08:45

I would like to know the difference between CompletableFuture,Future and Observable RxJava.

What I know is all a

4条回答
  •  伪装坚强ぢ
    2020-12-12 09:22

    All three interfaces serve to transfer values from producer to consumer. Consumers can be of 2 kinds:

    • synchronous: consumer makes blocking call which returns when the value is ready
    • asynchronous: when the value is ready, a callback method of the consumer is called

    Also, communication interfaces differ in other ways:

    • able to transfer single value of multiple values
    • if multiple values, backpressure can be supported or not

    As a result:

    • Future transferes single value using synchronous interface

    • CompletableFuture transferes single value using both synchronous and asynchronous interfaces

    • Rx transferes multiple values using asynchronous interface with backpressure

    Also, all these communication facilities support transferring exceptions. This is not always the case. For example, BlockingQueue does not.

提交回复
热议问题