I have an AEM OSGI Workflow application that makes a number of REST API calls as part of the workflow. For every REST call I am creating a new HttpClient instance and noticing some slow memory leak issues with this over a long period of time. The Apache documentation for HttpClient actually suggests to use a single instance of HttpClient throughout the lifetime of the application. Is something like this possible within AEM where I could maintain a single instance that can be used throughout each step of the workflow? Thanks for your help.
I'm referring to the HttpClient Performance Guide: HttpClient - HttpClient Performance Optimization Guide
Generally it is recommended to have a single instance of HttpClient per communication component or even per application. However, if the application makes use of HttpClient only very infrequently, and keeping an idle instance of HttpClient in memory is not warranted, it is highly recommended to explicitly shut down the multithreaded connection manager prior to disposing the HttpClient instance. This will ensure proper closure of all HTTP connections in the connection pool.
I've already modified a lot of the code so only one httpclient instance is created per step and noticed a difference. I also have scheduler services that iterate through number of requests. So was wondering if there was a way to refer to just one instance for all components of the application.