Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6924217

java.nio.channels.Selector causes unnecessary garbage collection

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 6u17
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      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 ----------

        Activity

        ndcosta Nelson Dcosta created issue -
        Hide
        alanb Alan Bateman added a comment -
        BT2:EVALUATION

        The garbage cited by the submitter will almost always be short lived and so will be efficiently handled by generational collectors used in most modern virtual machines. My guess is that this bug report was just a casual observation by the submitter. It did not include evidence that this is a real issue in practice.
        Show
        alanb Alan Bateman added a comment - BT2:EVALUATION The garbage cited by the submitter will almost always be short lived and so will be efficiently handled by generational collectors used in most modern virtual machines. My guess is that this bug report was just a casual observation by the submitter. It did not include evidence that this is a real issue in practice.

          People

          • Assignee:
            Unassigned
            Reporter:
            ndcosta Nelson Dcosta
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Imported:
              Indexed: