From cfbeeabf98d09e84ec9375c22515978d74f59a04 Mon Sep 17 00:00:00 2001 From: tursom Date: Wed, 27 May 2020 03:15:07 +0800 Subject: [PATCH] update --- .../kotlin/cn/tursom/niothread/ThreadPoolNioThread.kt | 10 ++++++++-- .../kotlin/cn/tursom/niothread/WorkerLoopNioThread.kt | 10 +++++++--- .../cn/tursom/niothread/loophandler/BossLoopHandler.kt | 9 +-------- .../tursom/niothread/loophandler/WorkerLoopHandler.kt | 9 +-------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/ThreadPoolNioThread.kt b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/ThreadPoolNioThread.kt index 34398d8..b5bae9c 100644 --- a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/ThreadPoolNioThread.kt +++ b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/ThreadPoolNioThread.kt @@ -16,7 +16,7 @@ class ThreadPoolNioThread( override lateinit var thread: Thread val threadPool: ExecutorService = ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, - LinkedBlockingQueue(), + LinkedBlockingQueue(), ThreadFactory { val thread = Thread(it) this.thread = thread @@ -35,7 +35,13 @@ class ThreadPoolNioThread( while (keyIter.hasNext()) { val key = keyIter.next() keyIter.remove() - workLoop(this@ThreadPoolNioThread, key) + try { + workLoop(this@ThreadPoolNioThread, key) + } catch (e: Exception) { + e.printStackTrace() + key.cancel() + key.channel().close() + } } } if (!threadPool.isShutdown) threadPool.execute(this) diff --git a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/WorkerLoopNioThread.kt b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/WorkerLoopNioThread.kt index 768bb38..0e90bee 100644 --- a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/WorkerLoopNioThread.kt +++ b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/WorkerLoopNioThread.kt @@ -25,7 +25,13 @@ class WorkerLoopNioThread( while (keyIter.hasNext()) { val key = keyIter.next() keyIter.remove() - workLoop(this, key) + try { + workLoop(this, key) + } catch (e: Exception) { + e.printStackTrace() + key.cancel() + key.channel().close() + } } } } catch (e: Exception) { @@ -115,6 +121,4 @@ class WorkerLoopNioThread( } } } - - } \ No newline at end of file diff --git a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/BossLoopHandler.kt b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/BossLoopHandler.kt index e62db72..b551a95 100644 --- a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/BossLoopHandler.kt +++ b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/BossLoopHandler.kt @@ -29,14 +29,7 @@ open class BossLoopHandler( } } } catch (e: Throwable) { - try { - protocol.exceptionCause(key, nioThread, e) - } catch (e1: Throwable) { - e.printStackTrace() - e1.printStackTrace() - key.cancel() - key.channel().close() - } + protocol.exceptionCause(key, nioThread, e) } } } \ No newline at end of file diff --git a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/WorkerLoopHandler.kt b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/WorkerLoopHandler.kt index fa73931..281908f 100644 --- a/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/WorkerLoopHandler.kt +++ b/AsyncSocket/src/main/kotlin/cn/tursom/niothread/loophandler/WorkerLoopHandler.kt @@ -19,14 +19,7 @@ class WorkerLoopHandler(private val protocol: NioProtocol) : (NioThread, Selecti } } } catch (e: Throwable) { - try { - protocol.exceptionCause(key, nioThread, e) - } catch (e1: Throwable) { - e.printStackTrace() - e1.printStackTrace() - key.cancel() - key.channel().close() - } + protocol.exceptionCause(key, nioThread, e) } } } \ No newline at end of file