3

I have a Spring Boot app with a @RestController and I'm using Undertow as the embedded server. Now, as far as I understand, Undertow's using two thread pools: A pool of IO threads handling the incoming requests and a pool of worker threads to which blocking tasks are delegated. As already answered here, Spring controller methods are called on one of the worker threads. However, the logic in the controller method might take some time to complete. So I was thinking about using Spring's support for asynchronous request processing by returning a Callable from the controller method. For example:

@RestController
public class MyController {

  @RequestMapping(path = "/myPath", method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public Callable<MyResult> handle() {

    // This part is handled by the Undertow worker thread
    doSomething();

    return () -> {
      // This part is handed off to a thread managed by Spring
      return doSomeLongerProcessing();
    };
  }
}

My question now is: Would you really use an additional thread pool for handling the longer running task? Or is it best practice to rather let everything run in the Undertow worker thread? As far as I understand that's exactly what the worker pool is for, right?

Community
  • 1
  • 1
martido
  • 373
  • 2
  • 9
  • What Waiting Strategy are you going to set the Worker Thread Mode to ? By default its blocking. so I wouldn't suggest dispatching it without changing the type. If not you'd be having a worker thread waiting in a blocked state for a response from your Spring managed ThreadPool – Vishnu667 Apr 18 '16 at 20:39
  • I didn't know that there's a Waiting Strategy. So I'm using the default. Thanks, will check it out. – martido Apr 19 '16 at 04:59

0 Answers0