[ 
https://issues.apache.org/jira/browse/CAY-1776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13510345#comment-13510345
 ] 

Nils Verheyen edited comment on CAY-1776 at 12/5/12 8:02 AM:
-------------------------------------------------------------

Hi Andrus, the application is quite complicated so i hope the following 
explanation is enough.

First of all, there is no special EventManager or configuration.

Inside the application some image processing is performed inside threads. I'm 
using a fixed thread pool of a maximum of 8 threads besides the main thread 
(Executors.newFixedThreadPool(8)). Each thread (main thread and the 8 worker 
threads) contains one ObjectContext created when an instance is initialized. 
This is done via DataContext.createDataContext();. Only in the main thread one 
single listener is added to the object context.

void addFlickrPhotoPostSizePersistListener(Object listener, String methodName) {

        LifecycleCallbackRegistry registry = 
objectContext.getEntityResolver().getCallbackRegistry();
        registry.addListener(LifecycleEvent.POST_PERSIST, PhotoSize.class, 
listener, methodName);
}

The method is called only once! The ObjectContext on the main thread is created 
during application launch and exists until the application is shut down.

Inside one of the 8 worker threads 256 Objects are created through one 
ObjectContext at max and persisted to the database (mysql at the moment). After 
a worker is done the context is not used anymore.

Inside the main thread thousands of Photo, PhotoSize and ProcessingJob objects 
are created and persisted to db.

At the moment I use Cayennes stable release 3.0.2. I'll try the different 
approaches beginning with #1.

I hope the explanation is enough, otherwise I try to extract some code.

Thank for the help,
Nils
                
      was (Author: ude-nils):
    Hi Andrus, the application is quite complicated so i hope the following 
explanation is enough.

Inside the application some image processing is performed inside threads. I'm 
using a fixed thread pool of a maximum of 8 threads besides the main thread 
(Executors.newFixedThreadPool(8)). Each thread (main thread and the 8 worker 
threads) contains one ObjectContext created when an instance is initialized. 
This is done via DataContext.createDataContext();. Only in the main thread one 
single listener is added to the object context.

void addFlickrPhotoPostSizePersistListener(Object listener, String methodName) {

        LifecycleCallbackRegistry registry = 
objectContext.getEntityResolver().getCallbackRegistry();
        registry.addListener(LifecycleEvent.POST_PERSIST, PhotoSize.class, 
listener, methodName);
}

The method is called only once! The ObjectContext on the main thread is created 
during application launch and exists until the application is shut down.

Inside one of the 8 worker threads 256 Objects are created through one 
ObjectContext at max and persisted to the database (mysql at the moment). After 
a worker is done the context is not used anymore.

Inside the main thread thousands of Photo, PhotoSize and ProcessingJob objects 
are created and persisted to db.

At the moment I use Cayennes stable release 3.0.2. I'll try the different 
approaches beginning with #1.

I hope the explanation is enough, otherwise I try to extract some code.

Thank for the help,
Nils
                  
> 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

Reply via email to