Skip to content

Commit d41c197

Browse files
committed
JAVA-610: only start cursor clean thread if cursor finalizer is enabled
1 parent d4584d9 commit d41c197

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

src/main/com/mongodb/Mongo.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ public Mongo( ServerAddress addr , MongoOptions options ) {
190190
_applyMongoOptions();
191191
_connector = new DBTCPConnector( this , _addr );
192192
_connector.start();
193-
_cleaner = new DBCleanerThread();
194-
_cleaner.start();
193+
194+
if (options.cursorFinalizerEnabled) {
195+
_cleaner = new CursorCleanerThread();
196+
_cleaner.start();
197+
} else {
198+
_cleaner = null;
199+
}
195200
}
196201

197202
/**
@@ -229,8 +234,12 @@ public Mongo( ServerAddress left , ServerAddress right , MongoOptions options )
229234
_connector = new DBTCPConnector( this , _addrs );
230235
_connector.start();
231236

232-
_cleaner = new DBCleanerThread();
233-
_cleaner.start();
237+
if (options.cursorFinalizerEnabled) {
238+
_cleaner = new CursorCleanerThread();
239+
_cleaner.start();
240+
} else {
241+
_cleaner = null;
242+
}
234243
}
235244

236245
/**
@@ -266,8 +275,12 @@ public Mongo( List<ServerAddress> seeds , MongoOptions options ) {
266275
_connector = new DBTCPConnector( this , _addrs);
267276
_connector.start();
268277

269-
_cleaner = new DBCleanerThread();
270-
_cleaner.start();
278+
if (options.cursorFinalizerEnabled) {
279+
_cleaner = new CursorCleanerThread();
280+
_cleaner.start();
281+
} else {
282+
_cleaner = null;
283+
}
271284
}
272285

273286
/**
@@ -305,8 +318,12 @@ public Mongo( MongoURI uri )
305318
}
306319

307320
_connector.start();
308-
_cleaner = new DBCleanerThread();
309-
_cleaner.start();
321+
if (_options.cursorFinalizerEnabled) {
322+
_cleaner = new CursorCleanerThread();
323+
_cleaner.start();
324+
} else {
325+
_cleaner = null;
326+
}
310327
}
311328

312329
/**
@@ -451,12 +468,14 @@ public void close(){
451468
_connector.close();
452469
} catch (final Throwable t) { /* nada */ }
453470

454-
_cleaner.interrupt();
471+
if (_cleaner != null) {
472+
_cleaner.interrupt();
455473

456-
try {
457-
_cleaner.join();
458-
} catch (InterruptedException e) {
459-
//end early
474+
try {
475+
_cleaner.join();
476+
} catch (InterruptedException e) {
477+
//end early
478+
}
460479
}
461480
}
462481

@@ -585,7 +604,7 @@ boolean isMongosConnection() {
585604
private WriteConcern _concern = WriteConcern.NORMAL;
586605
private ReadPreference _readPref = ReadPreference.primary();
587606
final Bytes.OptionHolder _netOptions = new Bytes.OptionHolder( null );
588-
final DBCleanerThread _cleaner;
607+
final CursorCleanerThread _cleaner;
589608

590609
org.bson.util.SimplePool<PoolOutputBuffer> _bufferPool =
591610
new org.bson.util.SimplePool<PoolOutputBuffer>( 1000 ){
@@ -706,9 +725,9 @@ String _toKey( MongoURI uri ){
706725

707726
}
708727

709-
class DBCleanerThread extends Thread {
728+
class CursorCleanerThread extends Thread {
710729

711-
DBCleanerThread() {
730+
CursorCleanerThread() {
712731
setDaemon(true);
713732
setName("MongoCleaner" + hashCode());
714733
}

0 commit comments

Comments
 (0)