Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: @Blocking #7228

Merged
merged 7 commits into from Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,21 @@
You can use the ann:core.annotation.Blocking[] annotation to mark methods as blocking.

If you set `micronaut.server.thread-selection` to `AUTO`, The Micronaut Framework offloads the execution of methods annotated with `@Blocking` to the IO thread pool (See: api:io.micronaut.scheduling.TaskExecutors[]).

NOTE: `@Blocking` only works if you are using `AUTO` thread selection. Micronaut Framework defaults to `MANUAL` thread selection since Micronaut 2.0. We recommend the usage of ann:scheduling.annotation.ExecuteOn[] annotation to execute the blocking operations on a different thread pool. `@ExecutesOn` works for both `MANUAL` and `AUTO` thread selection.

There are some places where the Micronaut framework uses ann:core.annotation.Blocking[] internally:

|===
|Blocking Type|Description

|link:{micronautapi}http/client/BlockingHttpClient.html[BlockingHttpClient]
| Intended for testing, provides blocking versions for a subset of api:http.client.HttpClient[] operations.
|link:{micronautapi}core/io/IOUtils.html[IOUtils]
| Reads the contents of a `BufferedReader` in a blocking manner, and returns that as a `String`.
|link:{micronautapi}context/env/BootstrapPropertySourceLocator.html[BootstrapPropertySourceLocator]
| Resolves either remote or local api:context.env.PropertySource[] instances for the current `Environment`.

|===

TIP: https://micronaut-projects.github.io/micronaut-data/latest/guide/[Micronaut Data] also utilizes `@Blocking` internally for some transaction operations, CRUD interceptors, and repositories.
1 change: 1 addition & 0 deletions src/main/docs/guide/toc.yml
Expand Up @@ -121,6 +121,7 @@ httpServer:
threadPools:
title: Configuring Server Thread Pools
blockingOperations: Blocking Operations
atBlocking: '@Blocking'
nettyPipeline: Configuring the Netty Pipeline
cors: Configuring CORS
https: Securing the Server with HTTPS
Expand Down