DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Java meets reactive programing

原文链接

Reactor is a reactive programming library for the Java language which provides the basis for developing non-blocking applications, thus representing a change in how we think about an application’s execution model.

Reactive Programming follows the Observerdesign pattern which means that when an object’s status changes, the other objects are notified and updated, thus reducing the inefficient use of resources.

Backpressure grants the Consumerof an asynchronous stream the ability to tell the Producerthe amount of data that must be sent to prevent the issuance of events at a rate that is faster than the processing capabilities. 反向驱动?

Reactor has two reactive types that implement the Publisher interface, but also provide a broad set of operators: *Flux*and Mono.

A Monoobject represents a single or empty value result (0..1) and allows deterministic generation from scratch or a sequence from arbitrary callback types. 相比较,多一个callback

drawbacks:

  • More intensive memory usage is needed to store large data-flows as they are maintained for a long time.

  • It may be a little different from conventional programming, and it may be hard to understand in the beginning.

  • Most of the complexities must be dealt with at the time of declaring the service.

  • It doesn’t work well for applications that have very little data flow, as it can deem simple programming unnecessarily complex, or possibly even affect the performance.