Morphia Thread Safety

853 views
Skip to first unread message

Mike

unread,
Jun 23, 2010, 2:24:54 PM6/23/10
to Morphia
Any comments on the thread safety of morphia? The underlying MongoDB
Java driver is said to be thread safe, but what about singleton
instances of Datastores?

DataStore ds = morphia.createDatastore(new Mongo(...), "my_db");

http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency

Thanks.

Scott Hernandez

unread,
Jun 23, 2010, 3:18:44 PM6/23/10
to mor...@googlegroups.com
That Datastore and support objects were written to be thread-safe, but
they have been re-factored significantly since the last time I took a
keen eye to them with that in mind.

The Datastore (and Mapper) should be as thread-safe as driver underneath it.

I think I posted a response a while about how I do scoping in guice
for my app, but here they are:

@Singleton Datastore
@Singleton Mongo
@Request MyServices/MyDAO (holds some user state)

We need to add this to the wiki :) I've added an issue to track them
(and the lack of them).

yuyou

unread,
Aug 18, 2010, 8:52:40 AM8/18/10
to Morphia
Hi all,

Please correct me if I misunderstood you guys.

When using Morphia in a Servlet environment, basically I could store
one instance of DataStore into the application context and use it
later in my servlet code like doPost()?
There is no need to get the datastore in the time when a servlet is
initialized?

Thanks.

Yu

Is it so that I could construct an instance

On Jun 23, 10:18 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> That Datastore and support objects were written to bethread-safe, but
> they have been re-factored significantly since the last time I took a
> keen eye to them with that in mind.
>
> The Datastore (and Mapper) should be asthread-safe as driver underneath it.
>
> I think I posted a response a while about how I do scoping in guice
> for my app, but here they are:
>
> @Singleton Datastore
> @Singleton Mongo
> @Request MyServices/MyDAO  (holds some user state)
>
> We need to add this to the wiki :) I've added an issue to track them
> (and the lack of them).
>
>
>
> On Wed, Jun 23, 2010 at 11:24 AM, Mike <michael.m...@gmail.com> wrote:
> > Any comments on thethreadsafety of morphia? The underlying MongoDB
> > Java driver is said to bethreadsafe, but what about singleton

Scott Hernandez

unread,
Aug 18, 2010, 11:18:58 AM8/18/10
to mor...@googlegroups.com
That is fine. 

The costly thing to create (and that which holds the pool of connections) is the Mongo instance, which is a local variable to the Datastore.
Reply all
Reply to author
Forward
0 new messages