[JAVA-4612] Use Cleaner for DBCursor cleanup when runtime is Java 9+ Created: 15/May/22  Updated: 28/Oct/23  Resolved: 21/May/22

Status: Closed
Project: Java Driver
Component/s: Performance
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Improvement Priority: Unknown
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

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.



 Comments   
Comment by Githook User [ 21/May/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Use Cleaner for DBCursor cleanup when runtime is Java 9+ (#948)

JAVA-4612
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/1e028ee6e4577615e374e22b20ed0b4ab5deca46

Generated at Thu Feb 08 09:02:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.