Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 46 reactive programming Implementing Reactive Systems with Reactive Programming While reactive programming lets you compose asynchronous and event driven applications dont lose sight of the overall goal To successfully build responsive distributed systems in a world of cloud and containers embracing the asynchronous execution model is essential Reactive programming addresses the asynchronous development model but you still need a task based concurrency model and nonblocking I O Eclipse Vert x provides these two missing pieces as well as RxJava friendly APIs The Vert x execution model is based on the concept of an event loop An event loop is a thread consuming events from a queue For each event it looks for a handler interested in the event and calls it Handlers are methods that receive an event as a parameter In this model your code can be single threaded while handling lots of concurrent and entangled tasks However this approach comes with some drawbacks The executed handlers must never block the event loop if they do the system loses its responsiveness and the number of unprocessed events in the queue rises Fortunately Vert x comes with a large ecosystem for implementing almost anything in an asynchronous and nonblocking way For instance Vert x provides building blocks for building modern web applications accessing databases and interacting with legacy systems Lets look at a few examples The Vert x hello world application code available online is the following package samples import io vertx core Vertx public class HttpApplication public static void main String args 1 Create a Vert x instance Vertx vertx Vertx vertx 2 Create the HTTP server
You must have JavaScript enabled to view digital editions.