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
val threadPool: ExecutorService = ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
LinkedBlockingQueue<Runnable>(),
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)

View File

@ -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(
}
}
}
}

View File

@ -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)
}
}
}

View File

@ -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)
}
}
}