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:
parent
61dd937d11
commit
c09d716d34
@ -142,18 +142,20 @@ abstract class SelectorImpl
|
||||
// Precondition: Synchronized on this, keys, and selectedKeys
|
||||
Set cks = cancelledKeys();
|
||||
synchronized (cks) {
|
||||
Iterator i = cks.iterator();
|
||||
while (i.hasNext()) {
|
||||
SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
|
||||
try {
|
||||
implDereg(ski);
|
||||
} catch (SocketException se) {
|
||||
IOException ioe = new IOException(
|
||||
"Error deregistering key");
|
||||
ioe.initCause(se);
|
||||
throw ioe;
|
||||
} finally {
|
||||
i.remove();
|
||||
if (!cks.isEmpty()) {
|
||||
Iterator i = cks.iterator();
|
||||
while (i.hasNext()) {
|
||||
SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
|
||||
try {
|
||||
implDereg(ski);
|
||||
} catch (SocketException se) {
|
||||
IOException ioe = new IOException(
|
||||
"Error deregistering key");
|
||||
ioe.initCause(se);
|
||||
throw ioe;
|
||||
} finally {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user