Reputation: 57
I have the following code:
vertx.executeBlocking( future -> {
// do something that takes more than 60 seconds
future.complete();
}, result -> {
// handle the result
});
If the code inside executeBlocking
takes more than 60 seconds to evaluate, then the BlockedThreadChecker
starts printing exceptions in the logs about blocking the main event thread. In situations where I don't use executeBlocking
, the warnings - as expected - are printed after only 2 seconds.
I know there are ways of disabling the BlockedThreadChecker
log messages entirely, but I want to keep them as I would like to be notified if I do block the event thread.
Is my code inside executeBlocking
actually blocking the main event thread? If it is, then now do I execute long-running tasks without blocking it? If it's not, then why are these messages being logged and how do I disable them (without disabling BlockedThreadChecker
entirely?
Many thanks.
Upvotes: 3
Views: 3008
Reputation: 9128
You haven't included your logs but I suspect they indicate the blocked thread is a worker thread.
The blocked thread checker, by default, warns you if an event loop is blocked for more than 2 seconds and, a worker, more than 60 seconds.
This is configurable in VertxOptions
, with maxEventLoopExecuteTime
and maxWorkerExecuteTime
.
VertxOptions vertxOptions = new VertxOptions()
.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime)
.setMaxWorkerExecuteTime(maxWorkerExecuteTime);
Note that both values must be expressed in nanoseconds.
Upvotes: 6