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 |
---|---|
Intended for testing, and provides blocking versions for a subset of api:http.client.HttpClient[] operations. |
|
Reads the contents of a |
|
Resolves either remote or local api:context.env.PropertySource[] instances for the current |
Tip
|
Micronaut Data also utilizes @Blocking for some transaction operations, CRUD interceptors, and repositories.
|