So, i've been having this small issue while attempting to use MongoDB (And java driver), using Servlets EJBs and EJB Timers, running on Jboss 4.2.3.
I create a mongo singleton like so
private static Mongo mongoSingleton = null;
private MongoSingleton()
{
}
public synchronized static Mongo getMongo() throws UnknownHostException
{
if(mongoSingleton == null)
{
MongoOptions options = new MongoOptions();
options.connectionsPerHost = 40;
mongoSingleton = new Mongo("localhost", options);
}
return mongoSingleton;
}
and then pass the instance between my stateless session beans (Which i use for database transactions) using
DB db = MongoSingleton.getMongo().getDB("data");
Unless i'm missing something, surely this should use the single instance created in the singleton, however when i check the Mongo console, i notice that extra connections are being created in the application after the Mongo instance is created, this seems to happen at odd times (Does not happen at every database transaction), and the mongoSingleton is never null after the initial instance is created.
I may be missing something simple, but any tips would be handy, cheers.