This commit is contained in:
tursom 2020-05-27 03:15:07 +08:00
parent c401579426
commit cfbeeabf98
4 changed files with 17 additions and 21 deletions

View File

@ -16,7 +16,7 @@ class ThreadPoolNioThread(
override lateinit var thread: Thread override lateinit var thread: Thread
val threadPool: ExecutorService = ThreadPoolExecutor(1, 1, val threadPool: ExecutorService = ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS, 0L, TimeUnit.MILLISECONDS,
LinkedBlockingQueue<Runnable>(), LinkedBlockingQueue(),
ThreadFactory { ThreadFactory {
val thread = Thread(it) val thread = Thread(it)
this.thread = thread this.thread = thread
@ -35,7 +35,13 @@ class ThreadPoolNioThread(
while (keyIter.hasNext()) { while (keyIter.hasNext()) {
val key = keyIter.next() val key = keyIter.next()
keyIter.remove() 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) if (!threadPool.isShutdown) threadPool.execute(this)

View File

@ -25,7 +25,13 @@ class WorkerLoopNioThread(
while (keyIter.hasNext()) { while (keyIter.hasNext()) {
val key = keyIter.next() val key = keyIter.next()
keyIter.remove() keyIter.remove()
workLoop(this, key) try {
workLoop(this, key)
} catch (e: Exception) {
e.printStackTrace()
key.cancel()
key.channel().close()
}
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -115,6 +121,4 @@ class WorkerLoopNioThread(
} }
} }
} }
} }

View File

@ -29,14 +29,7 @@ open class BossLoopHandler(
} }
} }
} catch (e: Throwable) { } catch (e: Throwable) {
try { protocol.exceptionCause(key, nioThread, e)
protocol.exceptionCause(key, nioThread, e)
} catch (e1: Throwable) {
e.printStackTrace()
e1.printStackTrace()
key.cancel()
key.channel().close()
}
} }
} }
} }

View File

@ -19,14 +19,7 @@ class WorkerLoopHandler(private val protocol: NioProtocol) : (NioThread, Selecti
} }
} }
} catch (e: Throwable) { } catch (e: Throwable) {
try { protocol.exceptionCause(key, nioThread, e)
protocol.exceptionCause(key, nioThread, e)
} catch (e1: Throwable) {
e.printStackTrace()
e1.printStackTrace()
key.cancel()
key.channel().close()
}
} }
} }
} }