|
28 | 28 | import java.util.Queue; |
29 | 29 | import java.util.concurrent.ConcurrentLinkedQueue; |
30 | 30 | import java.util.concurrent.ExecutorService; |
31 | | -import java.util.concurrent.Executors; |
32 | 31 | import java.util.concurrent.TimeUnit; |
33 | 32 | import java.util.concurrent.atomic.AtomicBoolean; |
34 | 33 | import java.util.concurrent.atomic.AtomicReference; |
@@ -75,18 +74,18 @@ public class KeyExchangeMessageHandler { |
75 | 74 | // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue |
76 | 75 | // new packets. |
77 | 76 |
|
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 | | - |
84 | 77 | /** |
85 | 78 | * An {@link ExecutorService} used to flush the queue asynchronously. |
86 | 79 | * |
87 | 80 | * @see #flushQueue(DefaultKeyExchangeFuture) |
88 | 81 | */ |
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); |
90 | 89 |
|
91 | 90 | /** |
92 | 91 | * The {@link AbstractSession} this {@link KeyExchangeMessageHandler} belongs to. |
@@ -209,7 +208,6 @@ public void shutdown() { |
209 | 208 | kexFlushedFuture.get()); |
210 | 209 | }); |
211 | 210 | items.getValue().setValue(Boolean.valueOf(items.getKey().intValue() == 0)); |
212 | | - flushRunner.shutdownNow(); |
213 | 211 | } |
214 | 212 |
|
215 | 213 | /** |
|
0 commit comments