简体   繁体   中英

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. In the context listener for the servlet an instance of MongoClient is defined, and there it connects to the database. 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.

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.

Thanks very much, apologies for the simple question,

Mark

I found that there was a memory leak else where in my 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!).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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