cancel
Showing results for 
Search instead for 
Did you mean: 

How to model a long-running java task?

jvoris
Champ in-the-making
Champ in-the-making
I have a long running java task (runs longer than 5 minutes) that generates a ActivitiOptimisticLockingException because a 2nd instance of the process is started after 5 minutes – well before the 1st instance of the process has a chance to finish.

This thread (http://forums.activiti.org/content/does-job-executor-launch-service-tasks-more-once) mentions the same problem, and in that thread there is mention of a send/receive solution – but there is no more explanation of what that means.

I've created a workaround where I have my own custom job executor that sets a 30 minute threshold for process completion instead of the default 5 minutes that works, but that doesn't seem like the ideal approach. Here is the bpm for the process:


    <process id="bankImportJob" name="Bank Import Job" isExecutable="true">
        <startEvent id="startevent1" name="Start" >
            <timerEventDefinition>
                <!– Run once a day at 7:00am. –>
                <timeCycle>0 0 7 ? * *</timeCycle>
            </timerEventDefinition>
        </startEvent>
        <serviceTask id="bankImportServiceTask" name="Bank Import" activiti:class="com.company.BankImportJob" />

        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="bankImportServiceTask" />
        <sequenceFlow id="flow2" sourceRef="bankImportServiceTask" targetRef="theEnd" />

        <endEvent id="theEnd" />
    </process>


What is a good/right way to model this so that I don't have to worry about how long the bankImportServiceTask runs?
1 REPLY 1

trademak
Star Contributor
Star Contributor
The default setting of the job executor is that it will start retrying a job if it's not completed within 5 minutes.
So your solution to override that for your use case is perfectly fine. Another way to solve this is via the send/receive task solution you mentioned. This is described in this blogpost:

http://bpmn20inaction.blogspot.nl/2012/12/implement-parallel-execution-in-activiti.html

Best regards,