I have an application that is finding one document from Mongo DB when a client is trying to login. While this works most of the times, it sometimes throws a timeout underneath "com.mongodb.MongoException$Network: can't call something : ..."
Once a request fails (after the preconfigured timeout), the next request seems to work fine but then some other call randomly fails with the same exception. The relevant part of the stack trace is
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:295)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCollection.findOne(DBCollection.java:727)
at com.mongodb.DBCollection.findOne(DBCollection.java:669)
I'm using Spring's MongoTemplate to get a collection and then query it for finding a single document. My Code Snippet would be something like that shown below
BasicDBObject query = new BasicDBObject();
query.put("myIntParam", 283);
DBCollection collection = mongoTemplate.getDb().getCollection(collectionName);
DBObject foundDocument = collection.findOne(query);
Same mongo template instance is getting used in the application for other reading and writing purposes in different collections (I think it is recommended to use only a single instance per app).
The problem usually comes after I leave the application idle for some time. I'm running on Ubuntu 12.10 server (my local env has desktop version for Ubuntu 12.10) with JDK 1.7 from within tomcat. Java Driver Version is 2.10.1. Following configuration options are supplied
mongoOptions.connectTimeout=5000
mongoOptions.socketTimeout=60000
mongoOptions.socketKeepAlive=true
mongoOptions.maxWaitTime=15000
mongoOptions.autoConnectRetry=true
Any suggestions or ideas?
Thanks in advance
删除mongoOptions.socketTimeout=60000
项目,或捕获超时异常,然后由您自己处理。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.