Skip to content

Instantly share code, notes, and snippets.

@arleighdickerson
Created July 13, 2025 16:44
Show Gist options
  • Save arleighdickerson/46d19ae095085db9418f4dbe18998578 to your computer and use it in GitHub Desktop.
Save arleighdickerson/46d19ae095085db9418f4dbe18998578 to your computer and use it in GitHub Desktop.
import io.undertow.connector.ByteBufferPool;
import io.undertow.server.DefaultByteBufferPool;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;
@Configuration
class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
private static final int POOL_BUFFER_SIZE = 16384;
private static final boolean POOL_USE_DIRECT_BUFFERS = true;
@Override
public void customize(UndertowServletWebServerFactory factory) {
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, createWebSocketDeploymentInfo());
});
}
private WebSocketDeploymentInfo createWebSocketDeploymentInfo() {
ByteBufferPool byteBufferPool = new DefaultByteBufferPool(POOL_USE_DIRECT_BUFFERS, POOL_BUFFER_SIZE);
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
webSocketDeploymentInfo.setBuffers(byteBufferPool);
webSocketDeploymentInfo.setDispatchToWorkerThread(true);
return webSocketDeploymentInfo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment