From e386bdb82c9a6fb7e740e4321167ac4afafa1d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my?= Date: Wed, 8 Jun 2022 11:49:22 +0200 Subject: [PATCH] Expose ThreadPoolTaskExecutor queue size and capacity for metrics We use Grafana to monitor our app via Spring's JMX exporter, and we think it could be interesting to have at least the current queue size for this purpose since the queue size directly affects the app memory load. Having the queue capacity seems also interesting to set up triggers whose values are calculated based on the maximum capacity of the queue. This commit introduces new getCurrentQueueSize() and getQueueCapacity() methods in ThreadPoolTaskExecutor. See gh-28583 --- .../concurrent/ThreadPoolTaskExecutor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java index 6a8334feeb..624191e234 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java @@ -315,6 +315,20 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport } return this.threadPoolExecutor.getPoolSize(); } + + /** + * Return the current number of threads waiting in the queue + */ + public int getCurrentQueueSize() { + return this.getThreadPoolExecutor().getQueue().size(); + } + + /** + * Return the maximum capacity of the queue + */ + public int getQueueCapacity() { + return this.queueCapacity; + } /** * Return the number of currently active threads.