cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Multithreaded application trouble with contexts
Date Thu, 17 Nov 2011 13:02:23 GMT
Hi Richard,
When to commit is really dependent upon the application, but a general
guide would be whenever your object graph is in a state that you want
to commit the changes.  Cayenne's DataContext (and supporting stack)
is thread-safe in that an application can have numerous DataContexts
doing queries and commits, but you shouldn't have multiple threads
sharing a DataContext without some kind of thread-safe controls over
it.

It sounds like your crawler needs to commit the URLs every time it
adds one, but even then I could see a situation where multiple threads
could insert the same URL.  Creating a thread-safe singleton that used
a single DataContext might be the best approach for you.  The
singleton would have addURL() type methods and those would manipulate
the DataContext in a thread-safe way and ensure no duplicates.

mrg


On Wed, Nov 16, 2011 at 6:00 PM, Richard Frovarp <rfrovarp@apache.org> wrote:
> What's the best strategy for doing frequent updates to the database with
> multiple threads?

Mime
View raw message