According to mongodb java concurrency driver we can use one instance of MongoClient
for multiple threads for example inside application servers. The only way I know to do this is to create MongoClient
in static block:
static {
MongoClient mongoClient = new MongoClient("localhost", 27017);
}
the problem is I can't catch MongoException
and return some helpfull information to user. So how to share a single instance of MongoClient
between multiple threads inside Java EE application servers?
You can do one of the following:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.