My strategy is to create a single Mongo() instance which is accessed
by all threads - I don't provide any locking around it, perhaps that's
naive. Once I've done this, I'm reading from it from multiple threads
via findOne() for my tests at the moment. The strange thing is that I
see multiple 'connection accepted' messages in the mongod console, and
then eventually I get some OOM errors like
java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:633)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
at com.mongodb.ByteEncoder.<init>(ByteEncoder.java:118)
at com.mongodb.ByteEncoder.<init>(ByteEncoder.java:47)
at com.mongodb.ByteEncoder$1.createNew(ByteEncoder.java:106)
at com.mongodb.ByteEncoder$1.createNew(ByteEncoder.java:109)
at com.mongodb.util.SimplePool._get(SimplePool.java:140)
at com.mongodb.util.SimplePool.get(SimplePool.java:106)
at com.mongodb.util.SimplePool.get(SimplePool.java:95)
at com.mongodb.ByteEncoder.get(ByteEncoder.java:92)
at com.mongodb.DBApiLayer$MyCollection.find(DBApiLayer.java:397)
at com.mongodb.DBCollection.findOne(DBCollection.java:245)
Is it expected to have multiple connections to the database when only
one Mongo() is instantiated? Is this even the right approach? Any
thoughts what might cause the above trace? Thanks for any hints.
Liam