(@NotNull SelectableChannel sc, int ops, @NotNull SelectorHandle handle)
| 125 | } |
| 126 | |
| 127 | @NotNull SelectionKey register(@NotNull SelectableChannel sc, int ops, @NotNull SelectorHandle handle) { |
| 128 | try { |
| 129 | //noinspection MagicConstant |
| 130 | SelectionKey key = sc.register(selector, ops, handle); |
| 131 | // 当引擎线程执行register时,wakeup会导致一次多余唤醒。 |
| 132 | // 这在连接建立不是很繁忙的应用中问题不大。 |
| 133 | // 下面通过判断是否本线程来决定是否调用wakeup。 |
| 134 | if (Thread.currentThread() != this) |
| 135 | selector.wakeup(); // 不会丢失。 |
| 136 | return key; |
| 137 | } catch (IOException e) { |
| 138 | throw Task.forceThrow(e); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | public void close() { |
| 143 | if (Thread.currentThread() == this) { |
nothing calls this directly
no test coverage detected