Scrivio Interview library
DebuggingFoundations7 min read · updated 12 November 2026

A Vert.x application logs the warning: Thread vert.x-eventloop-thread-2 has been blocked for 3400 ms. What does it mean and how do you fix it?

The warning means a handler running on event loop thread 2 has kept that thread busy for 3.4 seconds. Vert.x serves many connections with a few event loop threads, so while one is blocked, every handler assigned to it waits too; the blocked thread checker logs this once a handler exceeds the limit, 2 seconds by default. We find the blocking call (JDBC, file I/O, Thread.sleep or a synchronous HTTP client) from the stack trace, then move it to executeBlocking or a worker verticle, or replace it with a non-blocking client such as the Vert.x SQL client or web client; Vert.x 5 can also run verticles on virtual threads.

Why this question is asked

Vert.x is fast because it never waits: a handful of threads juggle thousands of connections by running short pieces of code and moving on. That design has one golden rule, do not block the event loop, and this warning is Vert.x telling us we broke it. Interviewers ask about it because it tests whether we understand the event loop model and the practical ways to keep blocking code away from it. In this answer, we will recap how event loops work, read the warning, find the blocking call, and fix it in three ways.

1A Quick Recap of the Event Loop

Vert.x creates a small number of event loop threads, by default two per CPU core. Each event loop runs in a cycle: take the next event, such as an incoming HTTP request or a database reply, run the handler registered for it, then take the next event. Each verticle and each connection is assigned to one event loop, and all its handlers run on that same thread.

This is efficient only if every handler returns quickly, in microseconds or a few milliseconds. If a handler blocks, by waiting for a database or sleeping, the thread cannot run anything else. All other requests on that event loop, possibly thousands of connections, wait in the queue. That is why one slow call can make a whole Vert.x service seem frozen.

2Reading the Warning

Vert.x runs a blocked thread checker in the background. Every second (blockedThreadCheckInterval) it looks at each event loop and measures how long the current task has been running. If it exceeds maxEventLoopExecuteTime, 2 seconds by default, it logs a warning naming the thread and the time. If the task keeps going past warningExceptionTime, 5 seconds by default, the warning also includes a stack trace of the blocked thread.

Java
WARNING: Thread Thread[vert.x-eventloop-thread-2,5,main] has been blocked for 3400 ms, time limit is 2000 ms
// To see a stack trace already at the first warning (useful while debugging):
Vertx vertx = Vertx.vertx(new VertxOptions()
.setWarningExceptionTime(2)
.setWarningExceptionTimeUnit(TimeUnit.SECONDS));

Notice that a 3400 ms block is past the warning limit but not past the 5 second stack trace limit, so with defaults we may see only the line without a trace. Lowering warningExceptionTime in a test environment makes Vert.x print the stack, which shows exactly which line was running. A thread dump taken during the stall, or a profiler, gives the same information.

3Finding the Blocking Call

The stack trace almost always ends in one of a few familiar places: a JDBC driver reading from a socket, java.io file access, Thread.sleep, a synchronous HTTP client such as java.net.http.HttpClient.send or RestTemplate, a lock or a blocking queue, or CPU-heavy work such as parsing a large file or hashing passwords. Here is a typical example.

Java
router.get("/report").handler(ctx -> {
String csv = reportDao.loadCsv(); // JDBC query, takes 3.4 s, runs on the event loop
ctx.response().putHeader("content-type", "text/csv").end(csv);
});
// While /report runs, every other request on vert.x-eventloop-thread-2 waits:
// GET /health on the same loop -> answered after 3.4 s instead of 1 ms
Step throughOne blocking handler stalls its event loop
Client AEvent loop 2DatabaseClient B
GET /report
JDBC query, thread blocked
GET /health, queued behind /report
rows after 3.4 s
CSV report
health answer, 3.4 s late

6 messages in order. Play them, or step through them one at a time.

Client B waits for Client A's query although its own handler takes 1 ms.

Notice the collateral damage: the health endpoint is fast code, but it shares the event loop, so it is delayed too. That is how a single slow report can make Kubernetes think the service is dead.

4Fix 1: Move It Off the Event Loop With executeBlocking

executeBlocking runs a piece of code on a worker thread from Vert.x's worker pool, 20 threads by default, and gives back a Future that completes on the original event loop. The event loop is free immediately.

Java
router.get("/report").handler(ctx ->
vertx.executeBlocking(() -> reportDao.loadCsv(), false) // false: tasks may run in parallel
.onSuccess(csv -> ctx.response().putHeader("content-type", "text/csv").end(csv))
.onFailure(ctx::fail));
// /health on the same event loop -> 1 ms again, while /report takes 3.4 s on a worker

Notice the second argument. By default executeBlocking is ordered, which means blocking tasks from the same context run one after another, never in parallel; for independent requests that would serialise every report. Passing false lets them run concurrently on the worker pool. Vert.x Web also offers blockingHandler on a route, which does the same job, and a worker verticle, a verticle deployed with the worker threading model, runs all its handlers on worker threads, which suits a component that is blocking by nature. The worker pool is finite, so long tasks need their own named pool, created with createSharedWorkerExecutor, to avoid starving others.

5Fix 2: Use Non-Blocking Clients, or Fix 3: Virtual Threads

The better long-term fix is not to block at all. The Vert.x SQL clients, such as the reactive PostgreSQL and MySQL clients, talk to the database asynchronously and call us back on the event loop when rows arrive. The Vert.x Web Client replaces synchronous HTTP clients, and vertx.fileSystem() offers asynchronous file operations.

Java
router.get("/report").handler(ctx ->
pgPool.query("SELECT id, total FROM orders WHERE day = current_date").execute()
.map(rows -> toCsv(rows))
.onSuccess(csv -> ctx.response().end(csv))
.onFailure(ctx::fail)); // no thread waits; the event loop keeps serving others
// Vert.x 4.5+ and 5: a verticle on virtual threads can block safely
vertx.deployVerticle(new ReportVerticle(),
new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD));

The last option combines the two worlds. In Vert.x 4.5 and later, including Vert.x 5, a verticle can be deployed with the virtual thread threading model, which needs Java 21 or later. Its handlers run on virtual threads, and inside them we can wait for a Future's result in plain sequential style without blocking an event loop; the exact await method differs between versions, so check yours. This is a good fit for code that is naturally sequential, such as legacy JDBC access, while hot paths stay on the event loop.

6Follow-up questions

Should I just raise maxEventLoopExecuteTime to silence the warning?

No. The warning is a symptom, and raising the limit only hides it while other requests still wait behind the blocked handler. The limit may be raised a little for known short CPU bursts at startup, but the real fix is to move blocking work off the event loop or use non-blocking APIs.

Is CPU-heavy work a problem too, even without I/O?

Yes. The event loop does not care why a handler takes long. Parsing a 50 MB JSON file or hashing a password with a high work factor keeps the thread just as busy as a database call. Such work belongs on a worker thread or a dedicated executor, sized to the number of cores.

What is the worker pool's default size and when should I change it?

The default worker pool has 20 threads. If many blocking tasks run at once, they queue behind each other, and the latency of each grows. We can raise the pool size in VertxOptions or create separate named worker executors for different kinds of work, so one slow kind cannot occupy all workers.

7Conclusion

In this answer, we saw that the warning means a handler kept an event loop thread busy for 3.4 seconds, past the 2 second default limit, which stalls every other handler on that thread. We found the blocking call from the stack trace, getting a trace earlier by lowering warningExceptionTime, and fixed it by moving it to executeBlocking or a worker verticle, by switching to non-blocking clients such as the Vert.x SQL client and web client, or by running the code on a virtual thread verticle in recent Vert.x versions.

What to say in the interviewAbout 90 seconds aloud

Open with

It means a handler on event loop thread 2 kept that thread busy for 3.4 seconds. Vert.x runs all handlers for a verticle or connection on one of a few event loop threads, by default two per core, so while that thread is blocked, every other request assigned to it waits, even trivial ones like a health check.

Then, if they want more

A background checker looks every second, and when a task runs longer than maxEventLoopExecuteTime, 2 seconds by default, it logs this warning. After 5 seconds it also prints a stack trace, so for a 3.4 second block I might lower warningExceptionTime in a test environment, or take a thread dump, to see the line.

It's almost always JDBC, file I/O, Thread.sleep, a synchronous HTTP client, or CPU-heavy work. To fix it, I'd move the call to vertx.executeBlocking, passing ordered false so independent requests don't serialise, or use blockingHandler in Vert.x Web, or put the component in a worker verticle.

Better long term is to use non-blocking clients: the Vert.x reactive SQL clients, the Web Client and the async file system. And with Vert.x 4.5 or 5 on Java 21, I can deploy a verticle with the virtual thread threading model and write sequential code there safely. I wouldn't just raise the limit, because that hides the stall.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. 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 "A Vert.x application logs the warning: Thread vert.x-eventloop-thread-2 has been blocked...": https://scrivio-interview-library.netlify.app/java/other-java-frameworks/4df3a1d51f/