最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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
Post a comment

comment list (0)

  1. No comments so far