Skip to content
Snippets Groups Projects
Commit 91f07916 authored by Jared Rosoff's avatar Jared Rosoff Committed by Robert J. Moore
Browse files

Don't use finalizers to close cursors

parent 218e2587
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,7 @@ public class MongoDbClient extends DB {
System.out.println("new database url = " + url);
MongoClientOptions options = MongoClientOptions
.builder()
.cursorFinalizerEnabled(false)
.connectionsPerHost(Integer.parseInt(maxConnections))
.threadsAllowedToBlockForConnectionMultiplier(
Integer.parseInt(threadsAllowedToBlockForConnectionMultiplier))
......@@ -373,6 +374,7 @@ public class MongoDbClient extends DB {
public int scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
com.mongodb.DB db = null;
DBCursor cursor = null;
try {
db = mongo.getDB(database);
db.requestStart();
......@@ -380,7 +382,7 @@ public class MongoDbClient extends DB {
// { "_id":{"$gte":startKey, "$lte":{"appId":key+"\uFFFF"}} }
DBObject scanRange = new BasicDBObject().append("$gte", startkey);
DBObject q = new BasicDBObject().append("_id", scanRange);
DBCursor cursor = collection.find(q).limit(recordcount);
cursor = collection.find(q).limit(recordcount);
while (cursor.hasNext()) {
// toMap() returns a Map, but result.add() expects a
// Map<String,String>. Hence, the suppress warnings.
......@@ -400,6 +402,9 @@ public class MongoDbClient extends DB {
}
finally {
if (db != null) {
if (cursor != null) {
cursor.close();
}
db.requestDone();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment