datastore class - getting com.mongodb.MongoInterruptedException

933 views
Skip to first unread message

koombal

unread,
Jul 19, 2014, 6:53:26 PM7/19/14
to mor...@googlegroups.com
Hi,

i am using DAOs with morphia, and i am seeing a strange behavior - if i am trying to use the same Datastore object to save/update more than once, then the 2nd time it fails and i am getting an exception: com.mongodb.MongoInterruptedException -

Causing: com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool 
! at com.mongodb.ConcurrentPool.acquirePermit(ConcurrentPool.java:172) ~[mongo-java-driver-2.12.2.jar:na]

and it happens in the same thread...

any ideas why it is happening to me? do i need to create a new datastore object for every DB access?...

thanks

koombal

unread,
Jul 20, 2014, 6:11:44 PM7/20/14
to mor...@googlegroups.com
I found the problem:

i did initialization code in a thread that was not garbage collected and the connection remained open.
subsequent usage of the datastore were failing from time to time afterwards (approximately every 2nd trial) due to some threading issues.

only when i removed the initialization code from that thread the problem gone away.

Justin Lee

unread,
Jul 21, 2014, 3:26:11 AM7/21/14
to mor...@googlegroups.com
Great!  Glad to hear you got that resolved.  I was just sitting down to type a response.  You shouldn't need to be re-creating these things often, though.  You can reuse datastores and MongoClients (where the actual connection lives in any case) through out your application.

--------------------------------

name     : "Justin Lee", 
  title    : "Software Engineer",
  twitter  : "@evanchooly",
  web      : [ "10gen.com", "antwerkz.com" ],
  location : "New York, NY" }


--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

koombal

unread,
Jul 21, 2014, 2:59:28 PM7/21/14
to mor...@googlegroups.com
Justin,

thanks for your response.

i am now reusing throughout the application the same MongoClient and Datastore object (actually the sane Datastore object).

1. Is that a good practice or should i create MongoClient/Datastore objects in different scenarios?
2. I still encounter from time to time the interrupted exception (not under load and under debugging sessions when the system has no load at all). I am not sure but could it be happening when i am trying to update a document that is not existing? the problem is that it is not consistent and sometimes it is not failing on that missing record... this is a very strange behavior.
3. can u think of something that might cause this kind of exception? we r using MongoDb and Morphia for the first time and afraid we'll have those issues when going to production...

We are using Dropwizard as our server container btw.

thanks
Reply all
Reply to author
Forward
0 new messages