更新时间:2023-09-13 09:05:04
MongoClient维护一个连接池,您一次使用MongoClient打开一个Db连接,并在您的应用程序中重复使用它,因为建立新的TCP连接在时间和内存上都是昂贵的明智的做法是重复使用连接的原因.另外,新的连接也会导致使用Db上的内存在MongoDB上创建新的线程.
The MongoClient maintains a connection pool,You open a Db connection once with MongoClient and reuse it across your application because setting up a new TCP connection is EXPENSIVE timewise and memory wise that's why you reuse connections. Also a new connection will cause a new Thread to be created on MongoDB using memory on the Db as well.