Question

We are currently re-architecting one of our JavaEE applications to leverage Morphia for modeling data in MongoDB. We use JavaEE 6 and Seam 2.x to provide the foundation for our application. My question is, what scope should we be using for Morphia Datastore and DAO objects? Is it safe to use Application scope and use a single instance throughout the application? Or should a more specific scope, like Request be used? Are there any concurrency or other issues that would prevent us from using Application scope?

Était-ce utile?

La solution

There's very little state in DatastoreImpl. There's the write concern, the mapper, and some decoder stuff. If these settings are universal for your application, which is usually the case, then this instance can be shared at the application scope just fine. If you use BasicDAO, then its only state is the entity class it operates on and the Datastore which we've already covered. This would also be generally safe to share.

Generally speaking, most of these components have very little mutable state that would break concurrent access. It's always a good idea to test, but in this case it's a pretty safe thing to do.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top