Board logo

标题: mongodb.MongoException$Network: can't call something [打印本页]

作者: look_w    时间: 2019-4-17 18:48     标题: mongodb.MongoException$Network: can't call something

java操作mongoDB的开发,实时插入mongoDB。

一开始是正常的,运行一段时间后开始报错。
长时间运行测试遇到问题,报错信息如下:

<Exception><Message><![CDATA[com.mongodb.MongoException$Network: can't call something]]></Message><StackTrace><![CDATA[com.mongodb.MongoException$Network: can't call something
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:296)
at com.mongodb.DB.command(DB.java:152)
at com.mongodb.DB._doauth(DB.java:496)
at com.mongodb.DB.authenticate(DB.java:433)
at com.bj58.groupbuy.framework.MongoUtils.MongoUtil.getCollection(MongoUtil.java:22)
at com.bj58.web.index.controllers.OtherController.userRecord(OtherController.java:328)
at sun.reflect.GeneratedMethodAccessor204.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bj58.wf.mvc.invoke.ActionInvoker.invoke(ActionInvoker.java:69)
at com.bj58.wf.mvc.MvcDispatcher.service(MvcDispatcher.java:103)
at com.bj58.wf.mvc.MvcFilter.doFilter(MvcFilter.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:284)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:322)
at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:1663)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.EOFException
at org.bson.io.Bits.readFully(Bits.java:37)
at org.bson.io.Bits.readFully(Bits.java:28)
at com.mongodb.Response.<init>(Response.java:35)
at com.mongodb.DBPort.go(DBPort.java:110)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:207)
... 26 more


怀疑是mongo的连接未关闭导致的,或者连接池用完  ,总之就是连接断开了

第一种java对mongodb的操作可以用如下方法设置:

    Mongo conn=new Mongo("127.0.0.1");
    MongoOptions option=conn.getMongoOptions();
    option.autoConnectRetry=true;
    option.socketTimeout=2000;
    option.socketKeepAlive=true;

试试设置这两个参数以后可以保持持久连接


option 还可以设置如下这些属性,根据需求选择:

    MongoOptions options = new MongoOptions();  

               options.autoConnectRetry = true;  

               options.connectionsPerHost = (200);  

               options.maxWaitTime = (200);  

               options.socketTimeout = (200);  

               options.connectTimeout = (200);  

               options.threadsAllowedToBlockForConnectionMultiplier = (200);  

               m = new Mongo(new ServerAddress("10.20.141.22", (200)), options);




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0