Its document says:
The client object is thread-safe and has connection-pooling built in.
This probably means we can create a single global MongoClient
and share it across multiple threads. But when do we call MongoClient.close
? Should it be called by each thread after that thread has finished database access, or should it be called only after all threads are done? If one thread calls MongoClient.close
, does that affect other threads that are accessing the database? Finally, should we reuse closed client instance or create a new one for the next database access?