[
https://issues.apache.org/jira/browse/CAY-1776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13509944#comment-13509944
]
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 (DispatchThread.run()). "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:
http://cayenne.apache.org/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html
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 decision.
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: https://issues.apache.org/jira/browse/CAY-1776
> 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 EventManager.java 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: http://www.atlassian.com/software/jira