When shutting down Log4J, e. g. during undeployment of a web application, the MongoClient opened by the MongoDbProvider must be closed by the MongoDbConnection.close() method. Otherwise the thread pool opened by the MongoClient will not get shutdown, since the MongoClient itself won't get closed.
The quick fix is to remove the comments
from the "close()" method of MongoDbConnection, as it's very misleading and, actually, wrong.
Instead, you really have to call
here, because the "close()" method of the MongoDbConnection is called only when shutting down NoSqlDatabaseManager using shutdownInternal().
My suggestion is to implement a similar strategy as used in the CouchDbConnection - using an AtomicBoolean flag to check whether "close()" has already been called.
This way the code also works for the new MongoDB Java driver 3.x API.