Skip to content

Commit e386bdb

Browse files
Rémysbrannen
authored andcommitted
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
1 parent 4912c3c commit e386bdb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ public int getPoolSize() {
315315
}
316316
return this.threadPoolExecutor.getPoolSize();
317317
}
318+
319+
/**
320+
* Return the current number of threads waiting in the queue
321+
*/
322+
public int getCurrentQueueSize() {
323+
return this.getThreadPoolExecutor().getQueue().size();
324+
}
325+
326+
/**
327+
* Return the maximum capacity of the queue
328+
*/
329+
public int getQueueCapacity() {
330+
return this.queueCapacity;
331+
}
318332

319333
/**
320334
* Return the number of currently active threads.

0 commit comments

Comments
 (0)