Hi Mike,
Unfortunately, I may have up to 200 simultaneous requests at the
database. I'm sure the database administrator won't like to see my app
opening and closing connections to their database so I would prefer to
open up a pool of connections and then share them among the incoming
requests much like a web app. I have no problem building the pool
solution but I just need to understand the best way to utilize the
Cayenne components and not duplicate or over-build what may already exist.
Or am I misunderstanding how createDataContext() works in that it is
already managing the pool of connections will only establish a new
connection when the requests exceed the number of already established
until the ConnectionPool limit is reached. If so, then what happens
when the (ConnectionPool + 1) createDataContext() request is made?
Andrew
On 04/30/2012 02:06 PM, Mike Kienenberger wrote:
At first I thought I could simple do a DataContext.createDataContext() and
I'd be fine but "Creating a new DataContext for each request is not a
recommended practice."
DataContext.createDataContext() is probably fine. The "request"
discussed above is a web server http request. It's unlikely that
you'll have hundreds of simultaneous threads in your standalone app.
Start with createDataContext() and see if it works well enough. If
not, then you can worry about finding another way to optimize it.
On Mon, Apr 30, 2012 at 1:36 PM, Andrew Willerding
<[email protected]> wrote:
I have built a few Web apps using Cayenne quite successfully but now I am
building my first standalone app and have a few questions.
In a Web app, I have typically just setup my Tomcat configuration and in my
code I execute something like ObjectContext context =
BaseContext.getThreadObjectContext() and let the "magic" happen.
In my standalone application I don't think it will be quite that easy. I
will have multiple short lived threads requesting database information
simultaneously so I'm not quite sure how to manage the Cayenne components.
At first I thought I could simple do a DataContext.createDataContext() and
I'd be fine but "Creating a new DataContext for each request is not a
recommended practice." So I understand the need for a single DataContext
and so I think I found the answer in createChildContext() but,
1) Do I need to manually create a child context in each thread? But what
should I do when the thread has completed its transactions and is ready to
terminate? I don't see a corresponding "destroyChildContext"
ObjectContext oc = getDataContext().createChildContext();
2) Or is it better to create a pool of ObjectContexts that I have to
manually manage access to within the threads - or does Cayenne have
something like this already built-in?
3) Is the maximum simultaneous createChildContext calls tied to the
ConnectionPool limits in the Modeler? To me the "createChildContext"
implies creation without limit so if they are somehow linked how will I know
that the underlying ConnectionPool has run out of resources?
4) Or am I way off base and making things more complicated than they should
be? ;-)
Sorry if I've missed the answers somewhere in the documentation but I
haven't been able to Google successfully for something I've fully
understood.
Thanks,
Andrew