-
Java concurrency and parallelism: barrier synchronizers (CountDownLatch, CyclicBarrier, Phaser)
Introduction
Barrier synchronizers (barriers) are a kind of synchronizer that ensures that any threads must stop at a certain point and cannot proceed further until all other threads reach this point.
By purpose, barriers can be grouped into the following categories:
- entry barriers, that prevents threads from starting processing
- exit barriers, that waiting for all threads to finish processing
Barriers also can be grouped by the number of iterations (one-time or cyclic) and by the number of parties/threads (fixed or variable).
In Java 7+ there are 3 predefined barrier classes: CountDownLatch, CyclicBarrier, Phaser.
-
Server-Sent Events (SSE) in Spring 5 with Web MVC and Web Flux
Introduction
There are no simple, general-purpose methods to implement asynchronous server-to-client communication in web applications with acceptable performance.
HTTP is a request-response protocol in the client-server computing model. To start an exchange, a client submits a request to a server. To finish the exchange, the server returns a response to the client. The server can send a response to only one client - the one that made the request. In the HTTP protocol, a client is the initiator of messages exchange.
There are cases when a server should be the initiator of exchange. One of the methods to implement this is to allow the server to push messages to clients in the publish/subscribe computing model. To start an exchange, a client subscribes to messages from the server. During the exchange, the server sends messages (as soon as they become available) to many subscribed clients. To finish the exchange, the client cancels the subscription.
Server-Sent Events (SSE) is a simple technology to implement asynchronous server-to-client communication for specific web applications.