On spring 5 responsive programming
In recent years, responsive programming is very popular in the developer community and customers. Due to its ability to build applications in a declarative way, rather than mandatory, it forms more sensitive and flexible applications. The fact that spring 5 incorporates reactive systems into its core framework has shown a paradigm shift towards declarative programming.
Responsive programming manages the asynchronous data flow between data producers and consumers, which need to respond to data in a smooth way. Therefore, responsive programming is both asynchronous and event driven smooth applications that require a small number of threads to scale.
Responsive programming is difficult to build a thread based architecture because of the high complexity involved in the process of application expansion based on shared variable states, threads and locks.
In the context of responsive programming, "when there is data in a stream, everything is a stream and behaves in a smooth manner."
Why responsive programming
High level abstraction and responsive programming lead to the improvement of code readability, so developers can mainly focus on the interdependence of events that define business logic.
In a highly concurrent environment, the response pattern is naturally suitable for message processing, which is a common enterprise use case.
Due to the characteristics of execution back pressure, the reactive method is best suited to control the flow between producers and consumers, which will help to avoid memory shortage.
For one or more threads, IO binding tasks can be executed asynchronously and non blocking without blocking the current thread.
In highly interactive and real-time applications or any operation / event, notifications of multiple connected subsystems may be triggered. In this case, responsive programming can be managed more effectively.
Ideal case for responsive programming implementation
Response streams
"Response flow" defines an API specification, which contains a minimum set of interfaces that disclose methods for defining operations and entities of non blocking backpressure data flow.
With the introduction of back pressure, response flow allows users to control the data exchange rate from publishers.
Response flow API Java util. concurrent. Flow has officially become a part of Java 9.
The response flow is mainly used as the interoperability layer.
Responsive programming provided by spring 5
Both spring web reactive module and spring MVC support the same @ controller programming, but spring web reactive is executed on reactive and non blocking engines.
Follow this document, see: http://docs.spring.io/spring-framework/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/web-reactive.html