We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Processor#run() 有如下的一个代码片段:
Processor#run()
SelectionKey key = null; try { key = iter.next(); iter.remove(); if (key.isReadable()) { read(key); } else if (key.isWritable()) { write(key); } else if (!key.isValid()) { close(key); } else { throw new IllegalStateException("Unrecognized key state for processor thread."); } }
这里是先判断了 isReadable()、isWritable(), 最后判断的 key.isValid(), 这里最好应该先判断 key.isValid(). 在判断 isReadable()、isWritable().因为在判断 isReadable()、isWritable() 之前 key 已经无效了, 所以可能会产生 CancelledKeyException.虽然在 catch 中最终会捕获到这个异常, 但是按照比较好的方式做的话, 应该还是先判断 key.isValid() 会更好一点.
isReadable()
isWritable()
key.isValid()
key
CancelledKeyException
catch
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Processor#run()
有如下的一个代码片段:这里是先判断了
isReadable()
、isWritable()
, 最后判断的key.isValid()
, 这里最好应该先判断key.isValid()
. 在判断isReadable()
、isWritable()
.因为在判断isReadable()
、isWritable()
之前key
已经无效了, 所以可能会产生CancelledKeyException
.虽然在catch
中最终会捕获到这个异常, 但是按照比较好的方式做的话, 应该还是先判断key.isValid()
会更好一点.The text was updated successfully, but these errors were encountered: