简体   繁体   English

MongoClient的实例可以长时间运行吗

[英]Can an instance of MongoClient be long running

This morning I found that my Java servlet (Tomcat 7) which interacts with Mongodb (using the standard Java Mongo driver) had failed after running for approximately 1.5 days. 今天早上,我发现与Mongodb交互的Java servlet(Tomcat 7)(使用标准的Java Mongo驱动程序)在运行约1.5天后失败。 In the context listener for the servlet an instance of MongoClient is defined, and there it connects to the database. 在Servlet的上下文侦听器中,定义了MongoClient实例,并在该实例中连接到数据库。 I then use this MongoClient instance to perform all my database interaction, in the separate functions I only call MongoClient.getDB(dbName) to get the database object which I then use to perform queries. 然后,我使用此MongoClient实例执行我的所有数据库交互,在单独的函数中,我仅调用MongoClient.getDB(dbName)来获取数据库对象,然后将其用于执行查询。

Have I done anything wrong? 我做错了什么吗? Should I be checking the connection is live or is this handled by the MongoClient object, I'm aware that it provides a pool of connections - so I assumed (mother of all mistakes) that it keeps connections to the database live with no management. 我应该检查连接是否处于活动状态,还是由MongoClient对象处理,我知道它提供了一个连接池-因此,我(所有错误的母亲)都假设它保持了与数据库的连接,并且没有任何管理。

Thanks very much, apologies for the simple question, 非常感谢,对于这个简单的问题表示歉意,

Mark 标记

I found that there was a memory leak else where in my servlet. 我发现在我的servlet中的其他地方存在内存泄漏。 Now it is fixed I am not having any problems. 现在已修复,我没有任何问题。 This means yes instances of MongoClient can see can be long running (so far mine has been running for over 2 days!). 这意味着可以,MongoClient实例可以长时间运行(到目前为止,我的运行已经超过2天了!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM