Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 1.48 KB

File metadata and controls

21 lines (14 loc) · 1.48 KB

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. @ExecutesOn works for both MANUAL or AUTO thread selection.

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

Blocking Type Description

BlockingHttpClient

Intended for testing, and provides blocking versions for a subset of api:http.client.HttpClient[] operations.

IOUtils

Reads the contents of a BufferedReader in a blocking manner, and returns that as a String.

BootstrapPropertySourceLocator

Resolves either remote or local api:context.env.PropertySource[] instances for the current Environment.

Tip
Micronaut Data also utilizes @Blocking for some transaction operations, CRUD interceptors, and repositories.