完成主代码后java.nio.channels.ClosedSelectorException

时间:2016-08-07 07:16:57

标签: java multithreading nio

我有一个主要代码

在完成后我得到了这个错误:

怎么可能?这意味着打开了一个新的后台线程?

我最终如何终止所有这些?

2016-08-07 00:00:42 ERROR linqmap.nio.NIOSelector Unexpected error in select loop
java.nio.channels.ClosedSelectorException
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:83)
    at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
    at linqmap.nio.NIOSelector.runSelector(NIOSelector.java:627)
    at linqmap.nio.NIOSelector$5.run(NIOSelector.java:477)
    at java.lang.Thread.run(Thread.java:745)
2016-08-07 00:00:42 ERROR linqmap.nio.NIOSelector Unexpected error in select loop
java.nio.channels.ClosedSelectorException
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:83)
    at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
    at linqmap.nio.NIOSelector.runSelector(NIOSelector.java:627)
    at linqmap.nio.NIOSelector$5.run(NIOSelector.java:477)
    at java.lang.Thread.run(Thread.java:745)
2016-08-07 00:00:42 ERROR linqmap.nio.NIOSelector Unexpected error in select loop
java.nio.channels.ClosedSelectorException
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:83)
    at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
    at linqmap.nio.NIOSelector.runSelector(NIOSelector.java:627)
    at linqmap.nio.NIOSelector$5.run(NIOSelector.java:477)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:2)

您在选择器位于select()内时将其关闭。

如果你试图阻止它,你应该设置一个每次围绕选择循环检查的布尔值,然后调用Selector.wakeup()

请注意,当准备就绪SelectionKeys时,选择循环必须应对被唤醒。