Is it possible to reuse MongoDB connection when multiple application servers connect to the mongodb server and restarted using java

Viewed 19

We have MongoDB on a separate server. There are multiple application servers and each will try to establish the connection to the MongoDB using MongoClientURI uri = new MongoClientURI(url.toString()); MongoClient client = new MongoClient(uri);

For example, if there are 10 application servers(tomcat) and each establishes connection on startup. So, now there are 10 connections to the mongodb.

Now, if any one of the application server restarts, it will again establish new connection to MongoDB. So the number of connections to MongoDB will be 11.

When a server restarts, how to close the previous connection and establish the new connection or is it possible to reuse the existing connection?

0 Answers
Related