cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrus Adamchik (JIRA)" <>
Subject [jira] [Commented] (CAY-1776) OutOfMemory during lifecycle events
Date Tue, 04 Dec 2012 18:54:58 GMT


Andrus Adamchik commented on CAY-1776:

Hi Nils, Thanks for the Jira.. Normally events added to the queue, are thereafter removed
from the queue by DispatchThreads and dispatched to the listeners (
"notifyAll" in your code example serves the the purpose of waking up dispatch threads and
start processing the queue...

So either you have a special EventManager configuration that prevents this from happening
(could you elaborate on "Inside my code a event listener is added once,"? do you have a custom
listener?), or indeed your app is so active that dispatch threads compete with commit threads
and the queue grows faster than it can be drained. 

If the later is the case, (meaning you have a lot of DataContexts, all committing in parallel),
there are a few ways you can approach a solution:

1. (Under 3.1) Set "cayenne.server.contexts_sync_strategy"  (aka Constants.SERVER_CONTEXTS_SYNC_PROPERTY)
to "false" (see "Changing Properties of Existing Services" here:
on how to set Cayenne properties). This will not disable the event dispatch, but it will prevent
peer contexts from listening to each other's events, so queue will be drained much faster.

2. (3.0 and 3.1) You can increase the number of dispatch threads. However this may still hit
the wall under higher load.

3. If nothing works, provide your own EventManager implementation that does nothing. 

I'd go with #1. It explicitly acknowledges that synchronizing the state of N peer DataContexts
does not scale to large values of N. So the solution is not a hack, but a conscious design

I;ll be curious to hear if the suggestions above fixed your issue (and please confirm, do
you actually have many parallel contexts committing?)

> OutOfMemory during lifecycle events
> -----------------------------------
>                 Key: CAY-1776
>                 URL:
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Lifecycle Extensions
>    Affects Versions: 3.0.2, 3.1B1
>         Environment: Linux x64, Mac OS X Lion
>            Reporter: Nils Verheyen
>            Priority: Minor
> Inside in Cayenne 3.0.2 and DefaultEventManager in Cayenne 3.1 there
is the inner class Dispatch with the following code:
> synchronized (eventQueue) {
>                     eventQueue.add(new InvocationDispatch(
>                             eventArgument,
>                             subject,
>                             invocation));
>                     eventQueue.notifyAll();
>                 }
> Inside my code a event listener is added once, but inside the eventQueue multiple InvocationDispatch
objects are created and never thrown away. When persisting thousands of objects the eventQueue
is filled up leading to OutOfMemory exceptions.
> Regards,
> Nils

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message