cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Standalone app, Threads and Object contexts
Date Wed, 02 May 2012 14:18:51 GMT
The number of ObjectContexts (or DataContexts) has no relation to the
number of database connections.  ObjectContexts are cheap to create and
use, so go wild.  Cayenne will do connection pooling out of the box by
using the minimum and maximum connection limits that you define in Modeler.

John

On Wed, May 2, 2012 at 8:05 AM, Andrew Willerding
<awillerding@itsurcom.com>wrote:

> On 05/02/2012 05:11 AM, Durchholz, Joachim wrote:
>
>> I'd probably look up the Cayenne docs on connection pooling, and just
>> make sure that everything is configured explicitly that the web container
>> would do for you implicitly. BTW I've been working on a J2SE application
>> for the last three years, and it's probably really a good idea to design
>> the application around "requests" or "transactions". Transactions can fail
>> due to transient errors, so you want them restartable, which means you need
>> to wrap them in objects, and there you have your requests. (This pattern
>> also sucks greatly because it isn't easy to pass results back to the
>> caller. Essentially, you're doing the exactly same web service
>> architecture, except it's running inside a single JVM.)
>>
> I got the impression that there was some sort of connection pooling
> built-in to Cayenne because in the Modeller there is a setting for minimum
> and maximum connections.  Now I'm getting confused and perhaps I'm using
> incorrect terminology.
>
> In my mind there is the actual connection to the database as defined
> during the creation of the DataContext.  In the application code I am
> creating an ObjectContext based on the DataContext with a call to
> DataContext.**createChildContext().  It is this ObjectContext where I can
> create/delete manipulate the contents of the database.
>
> But in a multi-threaded application do I need to create several
> ObjectContexts or can one ObjectContext be shared among all the threads?
>  If the ObjectContext is sharable then do I need to synchronize access to
> it?  If it needs to by synchronized then the "200th" thread will be in a
> long line-up which is why I would see the need to create several pooled
> ObjectContexts.  But then this takes be back to connection pooling as
> defined in the Modeller.  If everything goes back through a single
> connection then it's pointless to create and manage ObjectContexts as the
> bottleneck may be "deeper" in the Cayenne library.
>
> Help!  I getting trapped in my own recursive thoughts.
>
> ;-)
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message