AnsweredAssumed Answered

Problem Using Timer to Delay Re-executing Service Task

Question asked by ct1 on Nov 23, 2011
Latest reply on Dec 2, 2011 by ct1
I am trying to call a Service task that checks for the existance of a file.  I want the Service task to run, wait 5 minutes, and run again, until the file is found.

The Timer duration is set to PT1M.

When I start the process. The service task runs, logs its start, fails to find the file, waits, runs again, fails to find the file, and then throws an exception:

Nov 23, 2011 11:46:24 AM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource CheckForAFile.png
CheckForFile.execute() was called at Wed Nov 23 11:46:24 CST 2011
CheckForFile.lookForFile() was called with thePathName = "C:\Users\thomacha\DataFiles\" and theFileN
ame = "theFileToLookFor.txt".
In CheckForFile.lookForFile() set fileFound = false
In CheckForFile.execute() set fileExists = false.
File does NOT exist.
CheckForFile.execute() was called at Wed Nov 23 11:47:25 CST 2011
CheckForFile.lookForFile() was called with thePathName = "C:\Users\thomacha\DataFiles\" and theFileN
ame = "theFileToLookFor.txt".
In CheckForFile.lookForFile() set fileFound = false
In CheckForFile.execute() set fileExists = false.
File does NOT exist.
Nov 23, 2011 11:48:25 AM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[3424] was updated by another tra
nsaction concurrently
        at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:435)
        at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:348)
        at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:147
)
        at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:103)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInte
rceptor.java:49)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInter
ceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.j
ava:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.jav
a:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:6
3)
Nov 23, 2011 11:48:25 AM org.activiti.engine.impl.jobexecutor.JobAcquisitionThread run
SEVERE: exception during job acquisition: TimerEntity[3424] was updated by another transaction concu
rrently
org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[3424] was updated by another tra
nsaction concurrently
        at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:435)
        at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:348)
        at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:147
)
        at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:103)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInte
rceptor.java:49)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInter
ceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.j
ava:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.jav
a:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:6
3)
Nov 23, 2011 11:48:25 AM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource CheckForAFile.bpmn20.xml
Nov 23, 2011 11:48:25 AM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Nov 23, 2011 11:48:25 AM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes

I expected the cycle to continue uninterrupted.  What do you suggest I do?


Here is the BPMN2.0 file:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="CheckForAFile" name="CheckForAFile">
    <documentation>Place documentation for the 'CheckForAFile' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="checkFileExists"></sequenceFlow>
    <serviceTask id="checkFileExists" name="Check File Exists" activiti:class="opt.argo.com.CheckForFile"></serviceTask>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow2" name="" sourceRef="checkFileExists" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="doesExist" name="Yes" sourceRef="exclusivegateway1" targetRef="logThatFileExists">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${fileExists == true}]]></conditionExpression>
    </sequenceFlow>
    <scriptTask id="logThatFileExists" name="Log That File Exists" scriptFormat="groovy">
      <script><![CDATA[print "File does exist. \n"]]></script>
    </scriptTask>
    <sequenceFlow id="fileNotExist" name="File Does Not Exist" sourceRef="exclusivegateway1" targetRef="logThatFileNotExist">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${fileExists != true}]]></conditionExpression>
    </sequenceFlow>
    <scriptTask id="logThatFileNotExist" name="Log That File Does Not Exist" scriptFormat="groovy">
      <script><![CDATA[print "File does NOT exist. \n"]]></script>
    </scriptTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow3" name="" sourceRef="logThatFileExists" targetRef="endevent1"></sequenceFlow>
    <intermediateCatchEvent id="wait5minutes" name="Wait 5 Minutes">
      <timerEventDefinition>
        <timeDuration>PT1M</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="flow4" name="" sourceRef="logThatFileNotExist" targetRef="wait5minutes"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="wait5minutes" targetRef="checkFileExists"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_CheckForAFile">
    <bpmndi:BPMNPlane bpmnElement="CheckForAFile" id="BPMNPlane_CheckForAFile">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="150" y="220"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="checkFileExists" id="BPMNShape_checkFileExists">
        <omgdc:Bounds height="55" width="105" x="230" y="210"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40" width="40" x="430" y="217"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="logThatFileExists" id="BPMNShape_logThatFileExists">
        <omgdc:Bounds height="55" width="105" x="520" y="120"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="logThatFileNotExist" id="BPMNShape_logThatFileNotExist">
        <omgdc:Bounds height="55" width="105" x="520" y="300"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="760" y="220"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="wait5minutes" id="BPMNShape_wait5minutes">
        <omgdc:Bounds height="35" width="35" x="265" y="400"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="185" y="237"></omgdi:waypoint>
        <omgdi:waypoint x="230" y="237"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="335" y="237"></omgdi:waypoint>
        <omgdi:waypoint x="430" y="237"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="doesExist" id="BPMNEdge_doesExist">
        <omgdi:waypoint x="450" y="217"></omgdi:waypoint>
        <omgdi:waypoint x="450" y="147"></omgdi:waypoint>
        <omgdi:waypoint x="520" y="147"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="fileNotExist" id="BPMNEdge_fileNotExist">
        <omgdi:waypoint x="450" y="257"></omgdi:waypoint>
        <omgdi:waypoint x="450" y="327"></omgdi:waypoint>
        <omgdi:waypoint x="520" y="327"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="625" y="147"></omgdi:waypoint>
        <omgdi:waypoint x="777" y="147"></omgdi:waypoint>
        <omgdi:waypoint x="777" y="220"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="572" y="355"></omgdi:waypoint>
        <omgdi:waypoint x="572" y="417"></omgdi:waypoint>
        <omgdi:waypoint x="300" y="417"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="282" y="400"></omgdi:waypoint>
        <omgdi:waypoint x="282" y="265"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
Thank you.

Outcomes