Reuse of Iterator for SelectorThread.

This commit is contained in:
MobiusDev
2016-05-01 20:25:40 +00:00
parent 1d128bd778
commit 9d41bb9c0b

View File

@ -26,6 +26,7 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.LinkedList;
/**
@ -141,8 +142,12 @@ public final class SelectorThread<T extends MMOClient<?>>extends Thread
public final void run()
{
int selectedKeysCount = 0;
SelectionKey key;
MMOConnection<T> con;
Iterator<SelectionKey> selectedKeys;
while (!_shutdown)
{
try
@ -156,9 +161,13 @@ public final class SelectorThread<T extends MMOClient<?>>extends Thread
if (selectedKeysCount > 0)
{
for (SelectionKey key : _selector.selectedKeys())
selectedKeys = _selector.selectedKeys().iterator();
while (selectedKeys.hasNext())
{
_selector.selectedKeys().remove(key);
key = selectedKeys.next();
selectedKeys.remove();
con = (MMOConnection<T>) key.attachment();
switch (key.readyOps())