Configuring Undertow Pool size in Spring Boot

You can configure Undertow Pool size in Spring Boot applications through UndertowServletWebServerFactory. Let’s learn how to do it.

Out of the box, Undertow uses XNIO as the default connector. XNIO can be configured through the following settings:

  • io-threads: which is the number of IO threads to create. These threads are shared between multiple connections therefore they mustn’t perform blocking operations as while the operation is blocking, other connections will essentially hang. If not specified, a default will be chosen, which is calculated by cpuCount * 2.
  • task-max-threads: This is the maximum number workers allowed to run blocking tasks such as Servlet requests. In general terms, the default value of it (CPUs * 16) is reasonable default for most cases. If you see that new requests are being queued up, you should investigate the cause of it. If your application is working as expected, then you should increase this task-max-threads parameter.

That being said, here is how to use the UndertowServletWebServerFactory to configure Undertow’s pool size in Spring Boot:

@Bean public UndertowServletWebServerFactory embeddedServletContainerFactory() {
  UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
  int ioThreads = 5;
  int taskThreads = 100;
  return factory;
Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon