I’m trying to implement a thread-per-request design using Vert.x Web’s HTTP server. When I run the following code, I am not able to process any more requests until response.done()
is called:
final var server = vertx.createHttpServer(serverOptions).requestHandler(req -> {
// workerPool is a thread pool with 10 threads
workerPool.execute {
var response = req.response();
longRunningTask();
response.end("Done.")
}
})
I confirmed the culprit was response.done()
by changing my code to the following:
final var server = vertx.createHttpServer(serverOptions).requestHandler(req -> {
// workerPool is a thread pool with 10 threads
var response = req.response();
workerPool.execute {
longRunningTask();
}
response.end("Done.")
})
But this isn’t thread-per-request as I’m just offloading longRunningTask()
to a background thread, and quickly dealing with requests on the main thread.
I also tried:
Vertx#executeBlocking()
- Setting
workerPoolSize
to 5 - Setting
eventLoopPoolSize
to 5
and I got a similar result.
I’m on Java 17 and I’m using Vert.x Web 4.4.1 where it seems setting virtual threads and setting Vert.x’s threading model are not available. Any idea how to work around this?