Description
FULL PRODUCT VERSION :
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Server VM (build 14.3-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:01:29 UTC 2009 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Every select in java.nio.Selector, creates an Iterator. This is iterator is subsequently discarded. When continuously listening for data, Iterators are created and discarded unnecessarily, leading to garbage collection. There is no way to use the java.nio.Selector without avoiding garbage collection.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Any code that uses selector with multiple network connections. I've included a sample source code from the internet.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no garbage collection
ACTUAL -
garbage collection occurs frequently
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
<pre>
// Wait for events while (true) {
try {
// Wait for an event
selector.select();
} catch (IOException e) {
// Handle error with selector
break;
}
// Get list of selection keys with pending events
Iterator it = selector.selectedKeys().iterator();
// Process each key at a time
while (it.hasNext()) {
// Get the selection key
SelectionKey selKey = (SelectionKey)it.next();
try {
processSelectionKey(selKey);
} catch (IOException e) {
// Handle error with channel and unregister
selKey.cancel();
}
}
}
</pre>
---------- END SOURCE ----------
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Server VM (build 14.3-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:01:29 UTC 2009 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Every select in java.nio.Selector, creates an Iterator. This is iterator is subsequently discarded. When continuously listening for data, Iterators are created and discarded unnecessarily, leading to garbage collection. There is no way to use the java.nio.Selector without avoiding garbage collection.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Any code that uses selector with multiple network connections. I've included a sample source code from the internet.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no garbage collection
ACTUAL -
garbage collection occurs frequently
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
<pre>
// Wait for events while (true) {
try {
// Wait for an event
selector.select();
} catch (IOException e) {
// Handle error with selector
break;
}
// Get list of selection keys with pending events
Iterator it = selector.selectedKeys().iterator();
// Process each key at a time
while (it.hasNext()) {
// Get the selection key
SelectionKey selKey = (SelectionKey)it.next();
try {
processSelectionKey(selKey);
} catch (IOException e) {
// Handle error with channel and unregister
selKey.cancel();
}
}
}
</pre>
---------- END SOURCE ----------