首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Mongodb read timee out错误解决方法

2014-04-24 
Mongodb read timee out异常解决办法?org.springframework.dao.DataAccessResourceFailureException: can

Mongodb read timee out异常解决办法

?

org.springframework.dao.DataAccessResourceFailureException: can't call something : /172.16.9.54:27017/mo; nested exception is com.mongodb.MongoException$Network: can't call something : /172.16.9.54:27017/mo        at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:56)        at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1546)        at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1450)        at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1248)        at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1234)        at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:471)        at com.sitech.persistent.PhoneBillManagerImpl.queryMoSmsObjList(PhoneBillManagerImpl.java:144)        at com.sitech.mas.periodTask.impl.SmsMoPhoneBillTask.processTask(SmsMoPhoneBillTask.java:29)        at com.sitech.mas.periodTask.PeriodTaskHandler.doTask(PeriodTaskHandler.java:20)        at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:597)        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)        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:619)Caused by: com.mongodb.MongoException$Network: can't call something : /172.16.9.54:27017/mo        at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:292)        at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:256)        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:289)        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:274)        at com.mongodb.DBCursor._check(DBCursor.java:368)        at com.mongodb.DBCursor._hasNext(DBCursor.java:459)        at com.mongodb.DBCursor.hasNext(DBCursor.java:484)        at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1444)        ... 20 moreCaused by: java.net.SocketTimeoutException: Read timed out        at java.net.SocketInputStream.socketRead0(Native Method)        at java.net.SocketInputStream.read(SocketInputStream.java:129)        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)        at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)        at java.io.BufferedInputStream.read(BufferedInputStream.java:317)        at org.bson.io.Bits.readFully(Bits.java:46)        at org.bson.io.Bits.readFully(Bits.java:33)        at org.bson.io.Bits.readFully(Bits.java:28)        at com.mongodb.Response.<init>(Response.java:40)        at com.mongodb.DBPort.go(DBPort.java:124)        at com.mongodb.DBPort.call(DBPort.java:74)        at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:283)        ... 27 more

最后的read timed out是关键
异常原因是在进行数据操作时过长时间没有返回结果。

解决办法:设置SocketTimeout

spring配置如下:

<beans xmlns="http://www.springframework.org/schema/beans"
?????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?????? xmlns:mongo="http://www.springframework.org/schema/data/mongo"
?????? xsi:schemaLocation="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.2.xsd">

??? <!-- Connection to MongoDB server -->
??? <mongo:mongo id="replicaSetMongo" replica-set="192.168.1.190:27017">
??????? <mongo:options connections-per-host="100"
?????????????????????? threads-allowed-to-block-for-connection-multiplier="10"
?????????????????????? connect-timeout="30000"
?????????????????????? max-wait-time="5000"
?????????????????????? auto-connect-retry="true"
?????????????????????? socket-keep-alive="true"
?????????????????????? socket-timeout="5000"
?????????????????????? slave-ok="true"
?????????????????????? write-number="1"
?????????????????????? write-timeout="0"
?????????????????????? write-fsync="true"/>

??? </mongo:mongo>

??? <mongo:db-factory
??????????? id="mongoDbFactory"
??????????? host="192.168.1.190"
??????????? port="27017"
??????????? dbname="BD_BRANDSOURCE"
??????????? username=""
??????????? password=""/>

??? <bean id="mongoTemplate" ref="mongoDbFactory"/>
??????? <constructor-arg name="mongoConverter" ref="mappingConverter"/>
??? </bean>

??? <mongo:mapping-converter id="mappingConverter"/>

??? <!-- Package w/ automagic repositories -->
??? <mongo:repositories base-package="com.guangjieba.whale.repository.**"/>

</beans>

?

?

热点排行