Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4612

Use Cleaner for DBCursor cleanup when runtime is Java 9+

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.7.0
    • Affects Version/s: None
    • Component/s: Performance
    • None
    • Not Needed

      The DBCursor class has from its very beginning relied on Java's finalization mechanism to kill server-side cursors for abandoned un-exhausted DBCursor instances (ones that have not been fully iterated on the server and non explicitly killed). A couple of improvements have been made to the driver's use of this mechanism over the years, including:

      • moving the finalization to a separate, internal class whose instances are only created when there is actually a cursorId (and thus would require at least one getMore to exhaust the cursor
      • providing a way to disable finalization (though the default is still to leave it enabled)

      In Java 9, the Cleaner class was introduced to the JDK as a more performant alternative to finalization, but the driver does not rely on it because Java 8 is still the minimum supported version.

      However, the driver could still make use of Cleaner by detecting at runtime whether the Cleaner class is available, and only fall back to finalization if it's not.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: