Description
The method ElasticIndexStatistics.CountCacheLoader#reload creates a single-threaded executor to perform a query to Elastic in the background. However, it does not properly dispose of the thread pool. Notice that the code does not keep any reference to the executor that it creates, therefore it will never call shutdown to properly dispose of the executor and of the underlying thread. This will lead to an accumulation of unused threads, taking up memory and system resources.
public ListenableFuture<Integer> reload(@NotNull StatsRequestDescriptor crd, @NotNull Integer oldValue) { ListenableFutureTask<Integer> task = ListenableFutureTask.create(() -> count(crd)); Executors.newSingleThreadExecutor().execute(task); return task; }
Link to code in Git: https://github.com/apache/jackrabbit-oak/blob/5b1916dfd69e82759d80aff867d34bad94ea[…]ackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java
In addition to the resource leak, it is not good practice to create a new thread pool to execute a single request. A better alternative is to either use the ForkJoin pool provided by the Java runtime or to create a long-lived thread pool to execute these requests.
Attachments
Issue Links
- links to