I'm implementing web services using google guice framework, here I injected mongodb module with constructor initializes mongodb connection. Here for every method I am using MongoClient and do stuff then I close connection after getting results. The problem is that if there is extensive heavy computations connection get closed and give error could not bootstrap connection error. please find the way to implement mongodb connection that will keep alive or restart communicating...
try{
MongoDBModule module = new MongoDBModule();
MongoClient mongoClient = module.getMongoDBClient();
MongoDatabase database = mongoClient.getDatabase(m_client.getDatabaseName());
MongoCollection collection = database.getCollection("CAMPUS_PROD");
//do stuff with mongoclient
mongoClient.close();
return document.resuls
}catch(IOException ie){
// print exception
}