Spring RestTemplate to WebClient Causes OutOfMemoryError

Spring Boot is a highly popular framework for Java enterprise applications. One common method of integration with internal or external applications is through HTTP REST connections. We were upgrading from RestTemplate to the Java NIO-based WebClient, which can significantly enhance application performance by allowing concurrency when calling REST service endpoints. The benefits of WebClients are as follows:

  1. Concurrency: WebClient enables handling multiple connections simultaneously without blocking threads, leading to better concurrency.
  2. Asynchronous: Asynchronous programming allows the application to perform other tasks while waiting for I/O operations to complete, improving overall efficiency.
  3. Performance: Non-blocking I/O can manage more connections with fewer threads, reducing the resources required for handling concurrent requests.

Although the performance improved, however with the same number of concurrent connections, the WebClient was crashing with OutOfMemoryError. We will be analyzing the WebClient crash issues along with how to troubleshoot and fix them.

CategoriesUncategorized