6429289: (se) sun.nio.ch.SelectorImpl.processDeregisterQueue creates excessive garbage

Check if the cancelledKeys is empty or not before creating iterator

Reviewed-by: alanb
This commit is contained in:
Xueming Shen 2008-07-16 15:24:15 -07:00
parent 61dd937d11
commit c09d716d34

View File

@ -142,18 +142,20 @@ abstract class SelectorImpl
// Precondition: Synchronized on this, keys, and selectedKeys // Precondition: Synchronized on this, keys, and selectedKeys
Set cks = cancelledKeys(); Set cks = cancelledKeys();
synchronized (cks) { synchronized (cks) {
Iterator i = cks.iterator(); if (!cks.isEmpty()) {
while (i.hasNext()) { Iterator i = cks.iterator();
SelectionKeyImpl ski = (SelectionKeyImpl)i.next(); while (i.hasNext()) {
try { SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
implDereg(ski); try {
} catch (SocketException se) { implDereg(ski);
IOException ioe = new IOException( } catch (SocketException se) {
"Error deregistering key"); IOException ioe = new IOException(
ioe.initCause(se); "Error deregistering key");
throw ioe; ioe.initCause(se);
} finally { throw ioe;
i.remove(); } finally {
i.remove();
}
} }
} }
} }