我已经开始使用Vertex并出现了下一个问题。应用模式“Singleton”来处理MongoClient
对象是否正确?
这样的事情:
class Mongo {
private static volatile MongoClient mongoclient = null;
private Mongo(){};
public static MongoClient getInstance() {
if (mongoclient == null) {
synchronized(Mongo.class) {
if (mongoclient == null)
mongoclient = MongoClient.createShared(vertx, config);
}
}
return mongoclient;
}
}