最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

configuration - Micronaut Event Loop vs @ExecuteOn(TaskExecutors.BLOCKING) - Stack Overflow

programmeradmin1浏览0评论

So the Micronaut docs tell us that Micronaut uses an event loop:

Micronaut framework is built on Netty which is designed around an Event loop model and non-blocking I/O. Micronaut executes code defined in @Controller beans in the same thread as the request thread (an Event Loop thread).

And further says

To use the blocking executor, simply mark e.g. a controller with ExecuteOn

I'm looking for reasons that the given annotations might not work. I've tried both

@ExecuteOn(TaskExecutors.BLOCKING)

or

@ExecuteOn(TaskExecutors.IO)

but the thread used is still one of default-nioEventLoopGroup-2-3, etc

I have a blocking operation to execute, and it is failing with the error

io.micronaut.http.client.exceptions.HttpClientException: You are trying to run a BlockingHttpClient operation on a netty event loop thread. This is a common cause for bugs: Event loops should never be blocked. You can either mark your controller as @ExecuteOn(TaskExecutors.BLOCKING), or use the reactive HTTP client to resolve this bug. There is also a configuration option to disable this check if you are certain a blocking operation is fine here.

Alternatively, if anyone knows where/what that last mentioned "configuration option` is to disable the check, that would also be useful.

So the Micronaut docs tell us that Micronaut uses an event loop:

Micronaut framework is built on Netty which is designed around an Event loop model and non-blocking I/O. Micronaut executes code defined in @Controller beans in the same thread as the request thread (an Event Loop thread).

And further says

To use the blocking executor, simply mark e.g. a controller with ExecuteOn

I'm looking for reasons that the given annotations might not work. I've tried both

@ExecuteOn(TaskExecutors.BLOCKING)

or

@ExecuteOn(TaskExecutors.IO)

but the thread used is still one of default-nioEventLoopGroup-2-3, etc

I have a blocking operation to execute, and it is failing with the error

io.micronaut.http.client.exceptions.HttpClientException: You are trying to run a BlockingHttpClient operation on a netty event loop thread. This is a common cause for bugs: Event loops should never be blocked. You can either mark your controller as @ExecuteOn(TaskExecutors.BLOCKING), or use the reactive HTTP client to resolve this bug. There is also a configuration option to disable this check if you are certain a blocking operation is fine here.

Alternatively, if anyone knows where/what that last mentioned "configuration option` is to disable the check, that would also be useful.

Share Improve this question asked Nov 18, 2024 at 15:51 StewartStewart 18.3k8 gold badges56 silver badges84 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

happens to me as well. It turned out it is because I am using suspend function such as

    @ExecuteOn(TaskExecutors.BLOCKING)
    suspend fun greet(): String
发布评论

评论列表(0)

  1. 暂无评论