ITKeyword,专注技术干货聚合推荐

注册 | 登录

遇到的问题-----mongodb.MongoException$Network: can't call something

相关推荐:MongoDB can't call something 问题的解决办法

Java连接MongoDB的问题,程序跑了两天抛出这个异常:Exception in thread "main" com.mongodb.MongoException$Network: can't call something : /10.108.x.x:2

java操作mongoDB的开发,实时插入mongoDB。一开始是正常的,运行一段时间后开始报错。长时间运行测试遇到问题,报错信息如下:<Exception><Message><![CDATA[com.mongodb.MongoException$Network: can't call something]]></Message><StackTrace><![CDATA[com.mongodb.MongoException$Network: can't call somethingat 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.EOFExceptionat 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);

Spring 和mongodb集成的话,设置如下:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/data/mongo

http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <context:property-placeholder location="classpath*:META-INF/mongodb/mongodb.properties"/>

<!-- 定义mongo对象,对应的是mongodb官方jar包中的Mongo,replica-set设置集群副本的ip地址和端口 --> <mongo:mongo id="mongo" replica-set="localhost:27017">

<!-- 一些连接属性的设置 -->

<mongo:options

connections-per-host="${mongo.connectionsPerHost}"

threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}"

connect-timeout="${mongo.connectTimeout}"

max-wait-time="${mongo.maxWaitTime}"

auto-connect-retry="${mongo.autoConnectRetry}"

socket-keep-alive="${mongo.socketKeepAlive}"

socket-timeout="${mongo.socketTimeout}"

slave-ok="${mongo.slaveOk}"

write-number="1"

write-timeout="0"

write-fsync="true"/>

</mongo:mongo> <!-- mongo的工厂,通过它来取得mongo实例,dbname为mongodb的数据库名,没有的话会自动创建 --> <mongo:db-factory dbname="test" mongo-ref="mongo"/> <!-- mongodb的主要操作对象,所有对mongodb的增删改查的操作都是通过它完成 --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">

<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean>

<!-- 映射转换器,扫描back-package目录下的文件,根据注释,把它们作为mongodb的一个collection的映射 --> <mongo:mapping-converter base-package="com.xxx.xxx.domain" />

<!-- mongodb bean的仓库目录,会自动扫描扩展了MongoRepository接口的接口进行注入 --> <mongo:repositories base-package="com.xxx.xxx.persist.mongodb"/> <!-- To translate any MongoExceptions thrown in @Repository annotated classes --> <context:annotation-config />

</beans>

相关推荐:mongodb - Mongo Db Random Timeout when reading from Java Driver - Can't call something

in. While this works most of the times, it sometimes throws a timeout underneath "com.mongodb.MongoException$Network: can't call something : ..." O

java操作mongoDB的开发,实时插入mongoDB。一开始是正常的,运行一段时间后开始报错。长时间运行测试遇到问题,报错信息如下:<Exception><Message><![CDATA[com.mongodb.MongoExcept...

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。