驱动程序操作已中断(mongodb异常)

时间:2014-03-14 12:14:12

标签: mongodb-java

我正在为我的应用程序使用mongo数据库 用于连接假脱机,在创建连接时配置以下mongoOption

MongoOptions options = new MongoOptions();
   options.autoConnectRetry = true;
   options.connectionsPerHost = 40;
   options.threadsAllowedToBlockForConnectionMultiplier = 25;

虽然我的应用程序正常,但却出现以下异常

com.mongodb.MongoInterruptedException: A driver operation has been interrupted
at com.mongodb.DBPortPool.get(DBPortPool.java:216)
at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:440)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:177)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:349)
at com.mongodb.DBCollection.update(DBCollection.java:177)
at com.mongodb.DBCollection.save(DBCollection.java:817)
at com.mongodb.DBCollection.save(DBCollection.java:785)
at cherrypick.ck.datalayer.mongo.MongoDataAccessLayer.saveObject(MongoDataAccessLayer.java:361)
at cherrypick.ck.emailinterface.CKMailMonitor.processIncomingMessage(CKMailMonitor.java:170)
at cherrypick.ck.emailinterface.CKMailMonitor.monitorNewMessages(CKMailMonitor.java:253)
at cherrypick.ck.emailinterface.CKMailMonitor.run(CKMailMonitor.java:275)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1325)
at java.util.concurrent.Semaphore.tryAcquire(Semaphore.java:414)
at com.mongodb.util.SimplePool.permitAcquired(SimplePool.java:148)
at com.mongodb.util.SimplePool.get(SimplePool.java:110)
at com.mongodb.DBPortPool.get(DBPortPool.java:214)

任何人都可以帮我解决这个问题。

提前致谢  Raja Subramani

3 个答案:

答案 0 :(得分:1)

我最近遇到了这个例外。如果Thread已经中断并且您正在进一步尝试在同一线程上执行某些操作,则会发生这种情况。我通过使用java.lang.Thread

Thread.interrupted方法清除标志来处理此异常

答案 1 :(得分:0)

打开多个mongodb实例时会出现相同的错误。确保在打开新实例之前关闭mongo客户端。例如:

MongoClient mongo = new MongoClient ("localhost", 27017);

一定要做到: mongo.close(); 我希望它有所帮助

答案 2 :(得分:0)

之前我遇到过这个问题,它是由mongo数据库而不是你的代码造成的,所以你可以在你的配置文件中放大socket-timeout或者调用dba。