<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multiple instances of a ServiceTask class? in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87069#M58938</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I created an Jira issue with an attached unit test.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://jira.codehaus.org/browse/ACT-2165" rel="nofollow noopener noreferrer"&gt;https://jira.codehaus.org/browse/ACT-2165&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Dec 2014 10:13:03 GMT</pubDate>
    <dc:creator>schaumtier</dc:creator>
    <dc:date>2014-12-09T10:13:03Z</dc:date>
    <item>
      <title>Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87064#M58933</link>
      <description>My project uses a service task class implementing ActivityBehavior several times in multiple BPMN processes.&amp;nbsp; It looks to me that Activiti treats the service class as a singleton and only creates one instance of it, so that separate processes end up sharing state.Is there a configuration option to c</description>
      <pubDate>Wed, 24 Oct 2012 15:20:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87064#M58933</guid>
      <dc:creator>jonathan1</dc:creator>
      <dc:date>2012-10-24T15:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87065#M58934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;or should I just not store any state in the service task class?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;No, correct. as the documentation states, service tasks should be stateless&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 18:53:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87065#M58934</guid>
      <dc:creator>ronald_van_kuij</dc:creator>
      <dc:date>2012-10-24T18:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87066#M58935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can inject an expression. That expression will always be evaluated each time, if you evaluate it yourself in the service task.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;To inject values that are dynamically resolved at runtime, expressions can be used. Those expressions can use process variables, or Spring defined beans (if Spring is used). As noted in Service Task Implementation, an instance of the Java class is shared among all process-instances in a service task. To have dynamic injection of values in fields, you can inject value and method expressions in a org.activiti.engine.delegate.Expression which can be evaluated/invoked using the DelegateExecution passed in the execute method.&lt;BR /&gt;&lt;BR /&gt;&amp;lt;serviceTask id="javaService" name="Java service invocation" &lt;BR /&gt;&amp;nbsp; activiti:class="org.activiti.examples.bpmn.servicetask.ReverseStringsFieldInjected"&amp;gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; &amp;lt;extensionElements&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activiti:field name="text1"&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activiti:expression&amp;gt;${genderBean.getGenderString(gender)}&amp;lt;/activiti:expression&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/activiti:field&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activiti:field name="text2"&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activiti:expression&amp;gt;Hello ${gender == 'male' ? 'Mr.' : 'Mrs.'} ${name}&amp;lt;/activiti:expression&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/activiti:field&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;/ extensionElements&amp;gt;&lt;BR /&gt;&amp;lt;/ serviceTask&amp;gt;&lt;BR /&gt;The example class below uses the injected expressions and resolves them using the current DelegateExecution. Full code and test can be found in org.activiti.examples.bpmn.servicetask.JavaServiceTaskTest.testExpressionFieldInjection&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;public class ReverseStringsFieldInjected implements JavaDelegate {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; private Expression text1;&lt;BR /&gt;&amp;nbsp; private Expression text2;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; public void execute(DelegateExecution execution) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; String value1 = (String) text1.getValue(execution);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; execution.setVariable("var1", new StringBuffer(value1).reverse().toString());&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; String value2 = (String) text2.getValue(execution);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; execution.setVariable("var2", new StringBuffer(value2).reverse().toString());&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Oct 2012 07:36:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87066#M58935</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2012-10-25T07:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87067#M58936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have slightly different problem. I will explain using above example… &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In my case I have multiple instances of service task which has two fields, say “Text1” and “Text2”, but both are mutually exclusive. In the first instance the value for Text1 will be passed while for the second instance the value for Text2 will be passed. Here the first instance works properly. (Text1= somevalue, Text2=null) but the second instance is causing problem. Value for Text1 is not supplied to the second instance still the expression “text1.getValue(execution);” returns a value which is applicable to first instance. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any way to solve this problem. I mean a way to inject fields each time the instance is called or creating a new instance each time? Or any other way to solve this problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Nov 2014 05:49:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87067#M58936</guid>
      <dc:creator>chetan5p</dc:creator>
      <dc:date>2014-11-04T05:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87068#M58937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmm, i see. Could you provide a unit test that demonstrates this problem? Im actually unsure what the correct semantics should be by default.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 10:42:22 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87068#M58937</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2014-11-05T10:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87069#M58938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I created an Jira issue with an attached unit test.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://jira.codehaus.org/browse/ACT-2165" rel="nofollow noopener noreferrer"&gt;https://jira.codehaus.org/browse/ACT-2165&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 10:13:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87069#M58938</guid>
      <dc:creator>schaumtier</dc:creator>
      <dc:date>2014-12-09T10:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple instances of a ServiceTask class?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87070#M58939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;Hello I created two processes with two service tasks each as below&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;&lt;SPAN&gt;&amp;lt;definitions xmlns="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.omg.org/spec/BPMN/20100524/MODEL" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.omg.org/spec/BPMN/20100524/MODEL&lt;/A&gt;&lt;SPAN&gt;" xmlns:xsi="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/A&gt;&lt;SPAN&gt;" xmlns:activiti="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://activiti.org/bpmn" rel="nofollow noopener noreferrer" target="_blank"&gt;http://activiti.org/bpmn&lt;/A&gt;&lt;SPAN&gt;" xmlns:bpmndi="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.omg.org/spec/BPMN/20100524/DI" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.omg.org/spec/BPMN/20100524/DI&lt;/A&gt;&lt;SPAN&gt;" xmlns&lt;img id="smileysurprised" class="emoticon emoticon-smileysurprised" src="https://connect.hyland.com/i/smilies/16x16_smiley-surprised.png" alt="Smiley Surprised" title="Smiley Surprised" /&gt;mgdc="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.omg.org/spec/DD/20100524/DC" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.omg.org/spec/DD/20100524/DC&lt;/A&gt;&lt;SPAN&gt;" xmlns&lt;img id="smileysurprised" class="emoticon emoticon-smileysurprised" src="https://connect.hyland.com/i/smilies/16x16_smiley-surprised.png" alt="Smiley Surprised" title="Smiley Surprised" /&gt;mgdi="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.omg.org/spec/DD/20100524/DI" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.omg.org/spec/DD/20100524/DI&lt;/A&gt;&lt;SPAN&gt;" typeLanguage="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.w3.org/2001/XMLSchema&lt;/A&gt;&lt;SPAN&gt;" expressionLanguage="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.w3.org/1999/XPath" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.w3.org/1999/XPath&lt;/A&gt;&lt;SPAN&gt;" targetNamespace="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.activiti.org/test" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.activiti.org/test&lt;/A&gt;&lt;SPAN&gt;"&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;lt;process id="myProcess" name="My process" isExecutable="true"&amp;gt;&lt;BR /&gt;&amp;lt;startEvent id="startevent1" name="Start"&amp;gt;&amp;lt;/startEvent&amp;gt;&lt;BR /&gt;&amp;lt;serviceTask id="servicetask1" name="Service Task" activiti:expression="${businessRules.checkBalance(execution)}"&amp;gt;&amp;lt;/serviceTask&amp;gt;&lt;BR /&gt;&amp;lt;sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"&amp;gt;&amp;lt;/sequenceFlow&amp;gt;&lt;BR /&gt;&amp;lt;serviceTask id="servicetask2" name="Service Task" activiti:expression="${businessRules.addAccount(execution, context)}"&amp;gt;&amp;lt;/serviceTask&amp;gt;&lt;BR /&gt;&amp;lt;sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"&amp;gt;&amp;lt;/sequenceFlow&amp;gt;&lt;BR /&gt;&amp;lt;endEvent id="endevent1" name="End"&amp;gt;&amp;lt;/endEvent&amp;gt;&lt;BR /&gt;&amp;lt;sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="endevent1"&amp;gt;&amp;lt;/sequenceFlow&amp;gt;&lt;BR /&gt;&amp;lt;/process&amp;gt;&lt;BR /&gt;&amp;lt;/definitions&amp;gt;&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;businessRules is a bean I have configured in the activiti.cfg.xml file as below&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;&amp;lt;bean id="businessRules" class="com.company.BusinessRules" /&amp;gt;&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;Note that there are two service tasks in this process definition using expression to call method on the same bean. I also created a second process called "otherProcess" which is a mirror image of this process. I then ran both processes one after the other using the code below.&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();&lt;BR /&gt;RepositoryService repositoryService = processEngine.getRepositoryService();&lt;BR /&gt;repositoryService.createDeployment()&lt;BR /&gt;.addClasspathResource("MyProcess.bpmn20.xml")&lt;BR /&gt;.deploy();&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;repositoryService.createDeployment()&lt;BR /&gt;.addClasspathResource("OtherProcess.bpmn20.xml")&lt;BR /&gt;.deploy();&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;Map&amp;lt;string, object=""&amp;gt; variables = new HashMap&amp;lt;string, object=""&amp;gt;();&lt;BR /&gt;variables.put("context", new WorkflowContext());&lt;BR /&gt;RuntimeService runtimeService = processEngine.getRuntimeService();&lt;BR /&gt;ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess", variables);&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;Map&amp;lt;string, object=""&amp;gt; variables2 = new HashMap&amp;lt;string, object=""&amp;gt;();&lt;BR /&gt;variables2.put("context", new WorkflowContext());&lt;BR /&gt;ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("otherProcess", variables2);&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;processInstance2 = runtimeService.createProcessInstanceQuery().processDefinitionKey("otherProcess").singleResult();&lt;BR /&gt;System.out.println("Is Ended = " + processInstance.isEnded() + " Current Task: " + processInstance.getActivityId());&lt;/P&gt;&lt;P style="color: #717173; background-color: #fdfdff; margin: 0px 10px 1.2em 0px;"&gt;What I notice is that an instance of BusinessRules bean is only created once. I put a println message in the constructor of the BusinessRules and I see that it is hit only once across both processes, across the calls to the two service tasks in each process. Is this the expected behavior or should the BusinessRules bean be instantiated once per process, or once per service task? Thanks in advance for the clarification.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 17:02:58 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/multiple-instances-of-a-servicetask-class/m-p/87070#M58939</guid>
      <dc:creator>rohail</dc:creator>
      <dc:date>2014-12-18T17:02:58Z</dc:date>
    </item>
  </channel>
</rss>

