@@ -50,6 +50,7 @@ public void reset(){
5050 dbEncoderFactory = DefaultDBEncoder .FACTORY ;
5151 socketFactory = SocketFactory .getDefault ();
5252 description = null ;
53+ cursorFinalizerEnabled = true ;
5354 }
5455
5556 public MongoOptions copy () {
@@ -73,6 +74,7 @@ public MongoOptions copy() {
7374 m .dbEncoderFactory = dbEncoderFactory ;
7475 m .socketFactory = socketFactory ;
7576 m .description = description ;
77+ m .cursorFinalizerEnabled = cursorFinalizerEnabled ;
7678 return m ;
7779 }
7880
@@ -226,6 +228,16 @@ else if (safe)
226228 */
227229 public SocketFactory socketFactory ;
228230
231+ /**
232+ * Sets whether there is a a finalize method created that cleans up instances of DBCursor that the client
233+ * does not close. If you are careful to always call the close method of DBCursor, then this can safely be set to false.
234+ * @see com.mongodb.DBCursor#close().
235+ * Default is true.
236+ */
237+ public boolean cursorFinalizerEnabled ;
238+
239+
240+
229241 public String toString (){
230242 StringBuilder buf = new StringBuilder ();
231243 buf .append ( "description=" ).append ( description ).append ( ", " );
@@ -245,7 +257,8 @@ public String toString(){
245257 buf .append ( "w=" ).append ( w ).append ( ", " );
246258 buf .append ( "wtimeout=" ).append ( wtimeout ).append ( ", " );
247259 buf .append ( "fsync=" ).append ( fsync ).append ( ", " );
248- buf .append ( "j=" ).append ( j );
260+ buf .append ( "j=" ).append (j ).append ( ", " );
261+ buf .append ( "cursorFinalizerEnabled=" ).append ( cursorFinalizerEnabled );
249262
250263 return buf .toString ();
251264 }
@@ -538,4 +551,21 @@ public ReadPreference getReadPreference() {
538551 public void setReadPreference (ReadPreference readPreference ) {
539552 this .readPreference = readPreference ;
540553 }
554+
555+
556+ /**
557+ *
558+ * @return whether DBCursor finalizer is enabled
559+ */
560+ public boolean isCursorFinalizerEnabled () {
561+ return cursorFinalizerEnabled ;
562+ }
563+
564+ /**
565+ *
566+ * @param cursorFinalizerEnabled whether cursor finalizer is enabled
567+ */
568+ public void setCursorFinalizerEnabled (final boolean cursorFinalizerEnabled ) {
569+ this .cursorFinalizerEnabled = cursorFinalizerEnabled ;
570+ }
541571}
0 commit comments