Skip to content

Commit 7d77e6d

Browse files
Use a singleton threadpool for kex message handler flushing (#459) (fixes #458)
1 parent 7498f7a commit 7d77e6d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Queue;
2929
import java.util.concurrent.ConcurrentLinkedQueue;
3030
import java.util.concurrent.ExecutorService;
31-
import java.util.concurrent.Executors;
3231
import java.util.concurrent.TimeUnit;
3332
import java.util.concurrent.atomic.AtomicBoolean;
3433
import java.util.concurrent.atomic.AtomicReference;
@@ -75,18 +74,18 @@ public class KeyExchangeMessageHandler {
7574
// re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue
7675
// new packets.
7776

78-
/**
79-
* We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
80-
* readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
81-
*/
82-
protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
83-
8477
/**
8578
* An {@link ExecutorService} used to flush the queue asynchronously.
8679
*
8780
* @see #flushQueue(DefaultKeyExchangeFuture)
8881
*/
89-
protected final ExecutorService flushRunner = Executors.newSingleThreadExecutor();
82+
protected static ExecutorService flushRunner = ThreadUtils.newCachedThreadPool("kex-flusher");
83+
84+
/**
85+
* We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
86+
* readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
87+
*/
88+
protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
9089

9190
/**
9291
* The {@link AbstractSession} this {@link KeyExchangeMessageHandler} belongs to.
@@ -209,7 +208,6 @@ public void shutdown() {
209208
kexFlushedFuture.get());
210209
});
211210
items.getValue().setValue(Boolean.valueOf(items.getKey().intValue() == 0));
212-
flushRunner.shutdownNow();
213211
}
214212

215213
/**

0 commit comments

Comments
 (0)