Mongodb connection union

I am using the Java driver to access mongodb. I assume that db pooling is internally handled by the driver. But the number of connections increases every time I get access to db.

This is my serverStatus log.

"connections" : { "current" : 276, "available" : 543 } 

Do i need to explicitly close mongo connections? how do i manage the connection pool in java?

+6
source share
2 answers

You must use a single Mongo object, so it will make a pool for you. However, if you use multiple objects, you need to explicitly call .close() .

From: http://www.mongodb.org/display/DOCS/Java+Tutorial

The Mongo class is designed to provide thread safety and thread sharing. Usually you create only one instance for a given database cluster and use it in your application. If for some reason you decide to create, pay attention to the fact that:

all resource usage restrictions (maximum connections, etc.) apply to the mongo instance to delete the instance, make sure you call mongo.close () to clear the resources

+17
source

You can set the maximum pool size mongodb: // *** /? maxPoolSize = 5 for details, see this documentation https://docs.mongodb.com/manual/reference/connection-string/

0
source

Source: https://habr.com/ru/post/906630/


All Articles