Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

JavaDoc for DBCursor says that results are lazy-fetching from the database. But

public class DBApiLayer extends DB {
    ...
    private void init( Response res ){
    ...
       _cur = res.iterator()
    ...
    }
    Iterator<DBObject> _cur;
    ...
}

contains all items that match the query (and they take heap as I understand it). And concurrent db.collection.update(...) doesn't change those objects. Is storing all objects in heap thread safe implementation?

Please explain me what does 'lazy' and 'thread safe' mean in this case.

share|improve this question
For knowing lazy fetching : you can visit this site docs.mongodb.org/manual/core/read-operations/#cursor-behaviors . The doc says : "For most queries, the first batch returns 101 documents or just enough documents to exceed 1 megabyte. Subsequent batch size is 4 megabytes. To override the default size of the batch, see batchSize() and limit()" – Abhishek Kumar May 26 at 13:22
You are right. I tried on small collection about several thousands of records. I've just tried on a billion records and concurrent operation changed the count of cursor iterations. Thanks – katoquro May 26 at 17:07

1 Answer

up vote 0 down vote accepted

"Lazy" means that the next batch is requested lazily, as the client iterates over the DBCursor. So if you break out of the iteration early, the rest of the results are not fetched.

"Thread safe" in the page you referred to does not mean that every single class in the driver is safe to be used my multiple threads concurrently. In practice, MongoClient, DB, and DBCollection are thread safe, while DBCursor and DBObject are not.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.