-
@Target(value=PARAMETER) @Retention(value=RUNTIME) @Documented public @interface Suspended
Inject a suspendedAsyncResponse
into a parameter of an invoked JAX-RSresource or sub-resource method
. The injectedAsyncResponse
instance is bound to the processing of the active request and can be used to resume the request processing when a response is available.By default there is
no suspend timeout set
and the asynchronous response is suspended indefinitely. The suspend timeout as well as a customtimeout handler
can be specified programmatically using theAsyncResponse.setTimeout(long, TimeUnit)
andAsyncResponse.setTimeoutHandler(TimeoutHandler)
methods. For example:@Stateless @Path("/") public class MyEjbResource { … @GET @Asynchronous public void longRunningOperation(@Suspended AsyncResponse ar) { ar.setTimeoutHandler(customHandler); ar.setTimeout(10, TimeUnit.SECONDS); final String result = executeLongRunningOperation(); ar.resume(result); } private String executeLongRunningOperation() { … } }
A resource or sub-resource method that injects a suspended instance of an
AsyncResponse
using the@Suspended
annotation is expected be declared to returnvoid
type. Methods that inject asynchronous response instance using the@Suspended
annotation and declare a return type other thanvoid
MUST be detected by the JAX-RS runtime and a warning message MUST be logged. Any response value returned from such resource or sub-resource method MUST be ignored by the framework:@Path("/messages/next") public class MessagingResource { … @GET public String readMessage(@Suspended AsyncResponse ar) { suspended.put(ar); return "This response will be ignored."; } … }
- Since:
- 2.0
- Author:
- Marek Potociar
Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/ws/rs/container/Suspended.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.