From 5833c047a25b9ca9a32e49cd7c734aaa544288f8 Mon Sep 17 00:00:00 2001 From: Christoph Koras Date: Fri, 26 Jan 2024 18:46:07 +0100 Subject: [PATCH] Use a singleton threadpool for kex message handler flushing --- .../helpers/KeyExchangeMessageHandler.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java index 4ad8db4e1..a5853e06e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java @@ -28,7 +28,6 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -75,18 +74,18 @@ public class KeyExchangeMessageHandler { // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue // new packets. - /** - * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over - * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader. - */ - protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false); - /** * An {@link ExecutorService} used to flush the queue asynchronously. * * @see #flushQueue(DefaultKeyExchangeFuture) */ - protected final ExecutorService flushRunner = Executors.newSingleThreadExecutor(); + protected static ExecutorService flushRunner = ThreadUtils.newCachedThreadPool("kex-flusher"); + + /** + * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over + * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader. + */ + protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false); /** * The {@link AbstractSession} this {@link KeyExchangeMessageHandler} belongs to. @@ -209,7 +208,6 @@ public void shutdown() { kexFlushedFuture.get()); }); items.getValue().setValue(Boolean.valueOf(items.getKey().intValue() == 0)); - flushRunner.shutdownNow(); } /**