Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 33 reactive programming Elastic They stay responsive under varying workloads Resilient They stay responsive in the face of failure Responsive They respond in a timely manner This architectural style promotes a new way to build distributed systems infusing asynchrony into the core of these systems While reactive systems are described as distributed systems done right they can be dificult to build Taming the asynchronous beast is particularly dificult from the developer standpoint In addition the traditional threading model one thread per request tends to create memory and CPU hogs and when dealing with asynchronous code this approach is particularly inefficient Several development models have emerged to make the development of asynchronous applications easier including actors fibers coroutines and reactive programming This article focuses on the latter Reactive programming and its main derivative Reactive eXtensions or RX is an asynchronous programming paradigm focused on the manipulation of data streams It provides an API to compose asynchronous and event driven applications When using reactive programming you are handling streams of data in which data flows You observe these streams and react when new data is available But data streams have an inherent flaw What happens if you receive too many messages and you cant process them in time You could put a bufer between the source and the handler but it would help only with handling small bumps Dropping incoming data is also a solution but that is not always acceptable Ultimately you need a way to control the pace This is what the reactive streams specification proposes It defines an asynchronous and nonblocking back pressure protocol In this flow of control the consumer notifies the producer of its current capacity So the producer does not send too much data on the stream and your system autoadapts to its capacity without burning Why Do Reactive Systems Matter Why did reactive programming become so prevalent in the past few years For a very long time most applications have been developed using a synchronous execution model and
You must have JavaScript enabled to view digital editions.