Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
05. Aug 2008, 21:07 CET | Link

Hi, First, let me explain my problem at a high-level. I have a huge text file that contains CSV records, each record from this file has to be processed thru a workflow. So I set up a SLSB like such:

@Stateless
@Name("fileHandler")
public class FileHandlerImpl implements FileHandler {

        @In(create=true)
        private RecordProcessor recordProcessor;

        public void processFile(File file) {
                while (file has more records) {
                        read next record
                        recordProcessor.process(record);
                        update counters etc.
                }
        }
}

@Stateless
@Name("recordProcessor")
public class RecordProcessorImpl implements RecordProcessor {

        @Out(scope=BUSINESS_PROCESS)
        private String record;

        @CreateProcess("myworkflow")
        public void process(String record) {
                this.record = record;
        }
}

Everything works fine, except that the ManagedJbpmContext is created only once for all the invocations of RecordProcessor.process(). So the jBPM hibernate session keeps accumulating stuff until ALL the records in the file are processed. Here is the relevant log:

14:26:33,044 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,046 DEBUG [ManagedJbpmContext.create] created seam managed jBPM context
14:26:33,047 DEBUG [DbPersistenceServiceFactory.openService] creating persistence service
14:26:33,048 DEBUG [DbPersistenceService.getSession] creating hibernate session
14:26:33,107 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,131 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,156 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,226 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,256 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,280 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,304 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,329 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
14:26:33,382 TRACE [BusinessProcessInterceptor.afterInvocation] encountered @CreateProcess
... 1000's more entries like above
14:26:33,548 DEBUG [ManagedJbpmContext.beforeCompletion] flushing seam managed jBPM context
14:26:33,573 DEBUG [ManagedJbpmContext.beforeCompletion] done flushing seam managed jBPM context
14:26:33,583 DEBUG [ManagedJbpmContext.closeContext] destroying seam managed jBPM context

This is a problem because: 1. the file is quite large and causes transaction timeouts (fixable thru jboss.xml by increasing the timeout for processFile method) 2. the memory keeps growing since the underlying hibernate session isn't flushed and closed until all the records have been processed, this is causing OoM errors - I have profiled this using JProfiler

So my question is, is there a way to create and destroy the ManagedJbpmContext for every invocation of RecordProcessor.process() ? I am hoping that doing so will flush and close the hibernate session once per process instance (i.e. once per record). How can I do this?

I guess my other option would be to make RecordProcessor.process() asynchronous, but then I will have figure out how to update the counters based on process completion etc.

Any ideas or suggestions will be much appreciated

1 Reply:
05. Aug 2008, 21:09 CET | Link

Blast! I forgot to mention the following:

JBoss Seam 2.0.1 JBpm 3.2.2 JBoss AS 4.2.2 JDK 1.5.0

Thanks