Re: Selective commit

From: Michael Gentry (blacknex..mail.com)
Date: Mon Jan 07 2008 - 10:43:16 EST

  • Next message: Álvaro Martínez: "Re: Selective commit"

    Hi Álvaro,

    Creating a DataContext is a fairly cheap operation. I would suggest
    creating them as you need them and not try to optimize this operation
    at this point. If you run into bottlenecks in the future, then maybe
    look at other options, but there is a good chance that creating extra
    DataContexts will not be the source of a performance problem.

    /dev/mrg

    On Jan 7, 2008 10:30 AM, Álvaro Martínez <alvaro_martine..tbsl.com> wrote:
    >
    > Thanks, Andrus and Philip
    >
    > The threads I'm talking about are created from many sources and for
    > different reasons. Not of all them are triggered in response to
    > "something". There are also watchers, periodic tasks... So I can't map
    > data contexts to some particular condition.
    >
    > So then I have to create one data context per operation (that means a
    > set of actions). Is this expensive? We are developing a heavy loaded
    > cluster of servers, so it's important.
    >
    > Thanks again!
    >
    >
    > Andrus Adamchik escribió:
    >
    > > Hi Álvaro,
    > >
    > > It is hard to give a precise advice on multithreading without knowing
    > > the nature of your application. So here is a few general notes:
    > >
    > > * DataContext instance is your isolated area for making in-memory
    > > changes to objects that will all be committed at once. So consider
    > > using multiple contexts as appropriate. Cayenne docs recommend various
    > > common patterns, such as DataContext per session (i.e. each user has a
    > > dedicated context), DataContext per request, or DataContext per
    > > application (in a read-only app). You can also devise your own
    > > approach, if none of the above fit your needs. All you need to know
    > > here is that multiple threads *reading* from a shared DataContext is
    > > ok, but multiple threads *writing* to a shared DataContext is not ok.
    > >
    > > * In a rare case if you really need multiple threads to work off of
    > > the same context, consider using a dedicated nested DataContext for
    > > each atomic object modifications.
    > >
    > > Andrus
    > >
    > >
    > > On Jan 7, 2008, at 2:44 PM, Álvaro Martínez wrote:
    > >>
    > >> Hi, I've been working for a while with Cayenne but never realized I
    > >> had a problem... until I got a weird exception.
    > >>
    > >> The fact is that I had been using context.newObject() and
    > >> context.commitChanges() to create new rows in the database. But my
    > >> application works with many threads, so global commits can (and in
    > >> fact do) interrupt normal creation of objects. Thread A and Thread B
    > >> are creating objects and filling their fields, but then B commits all
    > >> and A throws a validation exception because mandatory fields are
    > >> missing.
    > >>
    > >> How could I commit only one object?
    > >>
    > >> Thanks,
    > >>
    > >> Álvaro from Spain (Push the button Inc.)
    > >>
    > >>
    > >>
    > >
    > >
    > >
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Jan 07 2008 - 10:43:49 EST