Asynchronous REST API with Jersey

We use jersey for the REST web service (deployed on tomcat).

I know that

  • The Tomcat HTTP Connector has a thread pool for reading HTTP requests and forwarding in Jersey.
  • Forwarding to Jersey synchronously.

I read here what jersey provides AsyncServiceto maximize concurrency.

Question: Why does the Jersey asynchronous project project developer turn off REST processing to split / runnable, while Jersey can do this on its own using a dedicated / private pool of executors?

Is this the best control for the developer, or am I not seeing something here?

+4
source share
1 answer

Why is a Jersey asynchronous project project developer turning off REST processing to split / runnable, while Jersey can do this on his own using a dedicated / private executor pool?

You are not forced. Jersey has @ManagedAsyncone that you can apply to your methods. It does exactly what you ask.

Managedasync

Indicates that the resource method to which the annotation was applied should be executed in a separate thread controlled by the Jersey backend service.

@GET
@ManagedAsync
public void longGet(@Suspended final AsyncResponse ar) {

}

See also:

+6
source

Source: https://habr.com/ru/post/1660102/


All Articles