Scrivio Interview library
InternalsFoundations6 min read · updated 12 November 2026

How many event-loop threads does Reactor Netty use by default in a Spring WebFlux application, and what are they responsible for?

By default Reactor Netty creates as many event-loop worker threads as there are available processors, with a minimum of 4, so an 8-core machine gets 8 and a 2-CPU container gets 4 (check your version; the count can be set with the reactor.netty.ioWorkerCount system property). These threads, named reactor-http-nio-N or reactor-http-epoll-N with native transport, perform all socket I/O and run our handler code unless it switches threads. Each connection is bound to one event loop for its lifetime, so any blocking call on a loop delays every connection that loop serves.

Why this question is asked

The event-loop threads are the heart of a WebFlux application. They are few, they are shared by every request, and almost every reactive performance problem comes down to what runs on them. Knowing how many there are and what they do lets us read a thread dump, size a container sensibly and recognise a blocked loop when latency spikes. Interviewers ask this internals question as a foundation for the debugging questions that usually follow. In this answer, we will recap what an event loop is, look at the default count and how to change it, see what the threads are responsible for, explain why connections are bound to one loop, and finish with the consequence for blocking code.

1A Quick Recap of an Event Loop

An event loop is a thread that runs a simple cycle forever: ask the operating system which of its sockets are ready (readable, writable, or with a new connection), handle those events, run any queued tasks, and repeat. Netty, the networking library under Reactor Netty, uses a selector (NIO) or the native epoll or kqueue APIs to ask that question for thousands of sockets at once. Because no thread waits on any one socket, a handful of threads can serve thousands of connections.

The model has one requirement: the code run for each event must be short. If one task takes 200 ms, the loop does not look at its other sockets for 200 ms.

2How Many Threads by Default

Reactor Netty creates its event loops in a shared LoopResources object. The number of worker threads defaults to Runtime.getRuntime().availableProcessors(), with a minimum of 4. availableProcessors respects container CPU limits on current JVMs, so a pod limited to 2 CPUs gets 4 workers, and a 16-core machine gets 16. The count can be changed with the system property reactor.netty.ioWorkerCount, or by providing our own LoopResources (check your version for the exact property names and defaults).

Java
// On an 8-core machine, a thread dump of an idle WebFlux service shows:
// "reactor-http-nio-1" RUNNABLE sun.nio.ch.KQueue.poll / EPoll.wait (waiting for socket events)
// ...
// "reactor-http-nio-8"
// With netty-transport-native-epoll on Linux: "reactor-http-epoll-1" ... "reactor-http-epoll-8"
// Customising the server's event loops in Spring Boot
@Bean
NettyServerCustomizer loops() {
return server -> server.runOn(LoopResources.create("http", 4, 16, true));
// selector threads 4, worker threads 16, daemon threads; check your version's signature
}

Notice that idle event loops show as RUNNABLE in a thread dump while sitting in the selector call. That is normal; it is the loop waiting for the operating system to report ready sockets.

By default Reactor Netty's HttpClient, which WebClient uses, shares the same global event loops as the server. So outgoing calls and incoming requests are handled by the same small set of threads, which is efficient but means a blocked loop slows both.

3What the Event-Loop Threads Do

The worker threads accept or are handed new connections, read bytes from sockets, decode HTTP, and pass the request to WebFlux. WebFlux then runs our controller or handler on that same thread, and every operator after it, unless something switches threads, for example publishOn, subscribeOn, or a time-based operator. When our Mono completes, the response is encoded and written on the connection's event loop. So in a typical non-blocking application, almost all our code runs on reactor-http-nio threads.

Step throughWork done on one event-loop thread
  1. Selector or epoll waitwhich of my sockets are ready?
  2. Read and decode HTTPbytes from the socket into a request
  3. WebFlux dispatchfind the controller or router function
  4. Our handler and operatorsruns here unless we switch threads
  5. Encode and write the responseback on the same loop
  6. Queued taskstimers, writes scheduled by other threads

6 layers, from the top down. Step through them one at a time.

Everything on this list shares one thread with every other connection on the loop.

4Each Connection Is Bound to One Event Loop

When Netty accepts a connection, it registers the connection's channel with one event loop from the group, chosen in turn, and that channel stays on that loop until it closes. All reads, writes and handler callbacks for that connection happen on that one thread. The reason is simplicity and speed: since one thread owns the channel, Netty needs no locks around its state, and data stays in that core's cache.

So with 8 loops and 4,000 open connections, each loop serves about 500 connections. That is the scale of the problem when a loop is blocked.

Connections spread across event loops
Event loopConnections bound to itIf this loop blocks for 100 ms
reactor-http-nio-1about 500about 500 connections wait 100 ms
reactor-http-nio-2about 500unaffected by loop 1
.........
reactor-http-nio-8about 500unaffected by loop 1
8 loops, 4,000 connections, assigned in turn.

5Why Blocking a Loop Is So Costly

Because each connection belongs to one loop, a blocking call on a loop thread, such as a JDBC query, a synchronous HTTP client, a file read or Thread.sleep, stops that loop from serving any of its other connections until the call returns. Their requests are not read, their responses are not written, and their timers do not fire. Latency rises for hundreds of unrelated requests while CPU stays low. That is why reactive code must never block on these threads, why blocking work is moved to Schedulers.boundedElastic(), and why Reactor refuses block() on them with an IllegalStateException.

6Follow-up questions

Should I increase the number of event loops for more throughput?

Usually not. Event loops are CPU-bound by design, so more loops than cores just adds context switching. If throughput is limited, the cause is normally blocking code on the loops or a slow dependency. Raising the count can hide a blocking problem slightly, but the fix is to remove the blocking.

Why does the default have a minimum of 4?

On very small machines or containers with one or two CPUs, a single slow task would otherwise freeze a large share of all connections. Four threads give a little resilience against occasional long tasks while still being cheap. It is a pragmatic default rather than a performance optimum.

Does WebFlux on Tomcat use the same model?

No. On a Servlet container, WebFlux uses the container's threads and its non-blocking I/O support, so the thread names and counts follow Tomcat's or Jetty's configuration. The rule not to block those threads still applies, because WebFlux still expects its threads to stay free.

7Conclusion

In this answer, we saw that Reactor Netty creates as many event-loop worker threads as available processors with a minimum of 4, configurable with reactor.netty.ioWorkerCount or custom LoopResources. These threads, named reactor-http-nio-N or reactor-http-epoll-N, perform the socket I/O and, by default, run our handler code and operators too, and the WebClient shares them. Each connection is bound to one event loop for its lifetime, which avoids locking but means any blocking call on a loop delays every connection that loop serves.

What to say in the interviewAbout 100 seconds aloud

Open with

By default Reactor Netty creates one event-loop worker thread per available processor, with a minimum of four. So an eight-core machine gets eight, and a container limited to two CPUs still gets four, since the JVM's availableProcessors respects container limits.

Then, if they want more

It can be changed with the reactor.netty.ioWorkerCount system property or by supplying custom LoopResources, and I'd check the exact defaults for the version in use. In a thread dump they show as reactor-http-nio-1 to N, or reactor-http-epoll with the native transport on Linux.

They're responsible for all the socket I/O: waiting on the selector for ready sockets, reading and decoding HTTP, and writing responses. And WebFlux runs our handler code on the same thread, along with every operator after it, unless something switches threads with publishOn or subscribeOn. By default WebClient shares the same event loops too.

Each connection is registered with one event loop when it's accepted and stays bound to it until it closes, which lets Netty avoid locks and keep data in one core's cache. With eight loops and four thousand connections, that's about five hundred connections per loop.

The consequence is that any blocking call on an event-loop thread, a JDBC query, a synchronous HTTP call, a file read, stalls every connection on that loop: requests aren't read, responses aren't written. Latency goes up while CPU stays low.

So blocking work has to go to boundedElastic or be replaced with non-blocking clients, and I'd use BlockHound in tests to catch it.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How many event-loop threads does Reactor Netty use by default in a Spring WebFlux...": https://scrivio-interview-library.netlify.app/spring-boot/webflux/c884f14035/