liveBook · Manning

Event loop

As explained in Spring in Action, Sixth Edition

An event loop is a concurrency mechanism that repeatedly receives events and dispatches their handlers, typically without dedicating a thread to each request.

An event loop handles many requests on relatively few threads by treating requests, callbacks, and completed operations as events. When a costly database or network operation begins, it registers a callback and continues processing other events instead of waiting. section 12.1

The event-loop approach supports reactive web applications by:

  • Handling many requests per thread, generally using about one thread per CPU core. section 12.1
  • Reducing per-connection and thread-management overhead under heavy request volume. section 12.1
  • Allowing Spring WebFlux to process requests through a nonblocking, asynchronous model based largely on Project Reactor. section 12.1

A costly operation

A request starts an intensive database or network operation. The event loop registers a callback, handles other events, and later processes the completed operation as another event. section 12.1

Figure 12.1 Asynchronous web frameworks apply event looping to handle more requests with fewer threads.

Use the figure to visualize how asynchronous web frameworks apply event looping to handle more requests with fewer threads. section 12.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains request, callback, and completion-event flow, then contrasts event-loop handling with servlet-based multithreading.
Examples
Illustrates callbacks for intensive database and network operations and visualizes handling more requests with fewer threads.
What you can do after
Apply it via Spring WebFlux when building reactive APIs that use nonblocking asynchronous request handling.
How it connects
Connects asynchronous web frameworks, callbacks, reactive types, Spring WebFlux, Project Reactor, and Spring MVC.

Also explained in

Compare how 11 books explain event loop →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.