Using ManagedExecutorService and server-side callbacks
In this section, we're going to take a look at using a ManagedExecutorService
instance for asynchronous request processing. I'm going to show you how to use CompletableFuture
to run and resume asynchronous requests. We will talk about using a TimeoutHandler
instance for fine-grained timer control, and we'll be using CompletionCallback
and ConnectionCallback
instances for even further control of the request processing.
Let's get started and switch to code. As usual, we prepare a template project to get started. The first thing we want to do is use a ManagedExecutorService
instance. Thus, we will inject this instance into our REST resource:
@Resource private ManagedEcecutorService executorService;
Then, we want to use this ManagedExecutorService
instance to do some heavy processing, such as processing Fibonacci numbers. We will use the ManagedExecutorService
instance and call the execute
method on it. In this execute
method, we then call...