Este contenido no está disponible en el idioma seleccionado.

Chapter 30. Asynchronous Job Service


The RESTEasy Asynchronous Job Service is an implementation of the Asynchronous Job pattern defined in O'Reilly's Restful Web Services. It is designed to add asynchronicity to a synchronous protocol.

30.1. Using Async Jobs

While HTTP is a synchronous protocol, it is capable of dealing with asynchronous invocations. The HTTP 1.1 response code 202 (Accepted) means that the server has received and accepted the response for processing, but that processing is not yet complete. The RESTEasy Asynchronous Job Service is based on this type of response.
POST http://example.com/myservice?asynch=true
Copy to Clipboard Toggle word wrap
For example, if you make the above post with the asynch query parameter set to true, RESTEasy returns a 202 (Accepted) response code and runs the invocation in the background. It also returns a Location header with a URL pointing to the location of the background method's response.
HTTP/1.1 202 Accepted
Location: http://example.com/asynch/jobs/3332334
Copy to Clipboard Toggle word wrap
The URI will have the form of:
/asynch/jobs/{job-id}?wait={millisconds}|nowait=true
Copy to Clipboard Toggle word wrap
You can perform GET, POST and DELETE operations on this job URL. GET returns the response of the JAX-RS resource method, if the job has completed. If the job has not completed, this GET returns a response code of 202 (Accepted). Invoking GET does not remove the job, so it can be called multiple times. When RESTEasy's job queue becomes full, it will evict the least recently used job from memory. You can clean the queue manually by calling DELETE on the URI. POST reads the JOB response and removes the JOB when it has completed.
Both GET and POST let you specify a mazimum wait time in milliseconds — a wait query parameter. For example:
POST http://example.com/asynch/jobs/122?wait=3000
Copy to Clipboard Toggle word wrap
If you do not specify a wait parameter, the GET or POST will not wait at all if the job is not complete.

Note

While you can invoke GET, DELETE, and PUT methods asynchronously, this breaks the HTTP 1.1 contract of these methods. These invocations may not change the state of the resource if invoked more than once, but they do change the state of the server. Try to invoke POST methods asynchronously.

Important

RESTEasy role-based security (annotations) does not work with the Asynchronous Job Service. You must use XML declarative security within your web.xml file. It is currently impossible to implement role-based security portably. In the future, we may have specific JBoss integration, but will not support other environments.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat