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.
;-)