From c3be46c36236b43d2e5c9654142315a327bd59f1 Mon Sep 17 00:00:00 2001 From: stobayiwa Date: Fri, 26 Jan 2024 16:33:25 +0200 Subject: [PATCH] add method to get remaining ThreadPoolTaskExecutor's queue capacity (#20) Co-authored-by: Stephen Tobayiwa --- .../handling/LongRunningMessageHandler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/mercateo/sqs/utils/message/handling/LongRunningMessageHandler.java b/src/main/java/com/mercateo/sqs/utils/message/handling/LongRunningMessageHandler.java index e18ae32c..e26dd194 100644 --- a/src/main/java/com/mercateo/sqs/utils/message/handling/LongRunningMessageHandler.java +++ b/src/main/java/com/mercateo/sqs/utils/message/handling/LongRunningMessageHandler.java @@ -205,5 +205,19 @@ public void shutdown() { messageProcessingExecutor.getThreadPoolExecutor().awaitTermination(10, TimeUnit.SECONDS); } } + /** + * Returns the number of elements that the {@link #messageProcessingExecutor} can accept + *

+ * This method should only be used in a single threaded environment, since it is possible that + * in a multi-threaded environment the number of free slots changes between the call to this method + * + * @return Remaining queue capacity + */ + public int getRemainingCapacity() { + return messageProcessingExecutor + .getThreadPoolExecutor() + .getQueue() + .remainingCapacity(); + } } \ No newline at end of file