MongoDB新的Java驱动的学习

MongoDB Java driver: autoConnectRetry (stackoverflow)

autoConnectRetry and maxAutoConnectRetryTime are deprecated in the current version最新版本中autoConnectRetry和maxAutoConnectRetryTime俩方法时被抑制的.

解释

There was a lot of confusion about the meaning of autoConnectRetry. Most people think it means that, if an operation failed due to an IOException, the driver would retry the operation until maxAutoConnectRetryTime elapsed. But that is not the case.

很多人对autoConnectRetry产生许多误解.人们错认为由于异常操作失败时,驱动会重试操作直到maxAutoConnectRetryTime的时间用尽.

All it means is that, on calls to Socket.connect(), the driver retries a failed attempt to connect until maxAutoConnectRetryTime elapsed. But this is exactly what connectTimeout is for. The only additional capability of autoConnectRetry is so that you can specify a longer connect timeout than is allowed by the underlying operating system (which typically enforces a max connect timeout that caps the value that the user specifies).

事实上它做的是socket连接,驱动会重试直到maxAutoConnectRetryTime的时间用尽.
但是这些是connectTimeout规定的内容.autoConnectRetry只是获得更长的 connect timeout,即连接超时.

Due to this confusion, the lack of value of the feature, and the fact that none of the other MongoDB drivers support this feature, we decided to deprecate it (and remove it in the next major release).

由于这些误解,并且事实上其他mongo驱动并未规定该类方法.我们决定抑制它(下版本将移除)

com.mongodb.DBPortPool gotError Warning: emptying DBPortPool to /IP:27017 b/c of error

MongoDB Driver can't remove dropped socket from connection from pool until your code try use it
原因
mongo驱动不能移除线程池中死掉的socket.

The MongoDB Java driver can only tell a connection is dead when you start to use it - it doesn't periodically check connections (for example) to check they're still alive because doing this automatically could have a performance impact. However, if you get an IOException in a single connection, all other connections will be closed and removed so new connections will be created afterwards.

java的 mngo驱动 只有当你用的时候,它才会告诉你连接已断开.驱动不会定期的检查连接是否正常.原因是这样会带来性能上的影响.另外,如果某一个连接抛了异常,剩余别的连接会关掉,移除连接.再操作时会建立新的连接.

It does mean that applications have a responsibility to catch Exceptions and perform a retry if appropriate. Really your application is the best place to decide what to do in exceptional circumstances like connections disappearing.

所以你的应用应该捕捉异常进行重试连接.

方案
add an interceptor method before every action in my application, and which will call a connection to check if it is closed.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,482评论 0 23
  • 导师活动,我们来到了北海公园进行小型的春游。 走进北海 春的气息扑面而来 春回大地,万物复苏 所有的生物都感受到春...
    安好晴天阅读 1,020评论 0 1
  • 谁都喜欢占便宜,我也喜欢;但是,得有个度吧。刚刚发生件有点不开心的事,我在朋友的朋友的微信上买了5斤大樱桃,晚上到...
    才少说阅读 1,124评论 0 1
  • 秋已随着被冬风吹落的梧桐树叶悄然离去,只留下一地的荒芜与凄凉。昨日,你还睡在我的上铺打呼噜说梦话;昨日,你还坐在我...
    吃蔬菜的狮子阅读 1,722评论 0 0