How to keep the connection pool from closing with a java driver on a mongodb?

MongoClientOptions options = new MongoClientOptions.Builder().socketKeepAlive(true).build();

socketKeepAlive is now Deprecated.
It now defaults to true and disabling it is not recommended.


https://api.mongodb.com/java/3.1/com/mongodb/MongoClientOptions.html

Look at the link. There are several method that can probably help you. Look into the timeout related methods for connection and connection pool.


EDIT: added the correct answer (it was in the comments below)

MongoClientOptions options = new MongoClientOptions.Builder().socketKeepAlive(true).build(); 
MongoClient client = new MongoClient("host", options);