<?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 How to handle a race condition signaling an Execution in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12852#M5663</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; We start long-running workflows that wait for a signal. &amp;nbsp;When certain events happen, we signal the workflow by searching for the list of Executions waiting on the signal (and some other criteria). &amp;nbsp;This can lead to race conditions because the incoming events can come in short order. &amp;nbsp;Here is example code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;ExecutionQuery &lt;SPAN class=""&gt;query&lt;/SPAN&gt; = &lt;SPAN class=""&gt;runtime&lt;/SPAN&gt;.createExecutionQuery().processVariableValueEquals(&lt;SPAN class=""&gt;"Key"&lt;/SPAN&gt;, k&lt;SPAN class=""&gt;ey&lt;/SPAN&gt;).signalEventSubscriptionName(&lt;SPAN class=""&gt;&lt;STRONG&gt;&lt;EM&gt;signalName&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;executions&lt;/SPAN&gt;.forEach(&lt;SPAN class=""&gt;ex&lt;/SPAN&gt; -&amp;gt; {&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;EM&gt;logger&lt;/EM&gt;&lt;/SPAN&gt;.info(&lt;SPAN class=""&gt;"Signaling workflow: "&lt;/SPAN&gt; + &lt;SPAN class=""&gt;ex&lt;/SPAN&gt;.getId() + &lt;SPAN class=""&gt;" with "&lt;/SPAN&gt; + &lt;SPAN class=""&gt;&lt;STRONG&gt;&lt;EM&gt;signalName&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;runtime&lt;/SPAN&gt;.signalEventReceived(&lt;SPAN class=""&gt;&lt;STRONG&gt;&lt;EM&gt;signalName&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;SPAN class=""&gt;ex&lt;/SPAN&gt;.getId(), &lt;SPAN class=""&gt;signalVars&lt;/SPAN&gt;);&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that the long-running workflow performs a few checks right after the signal is received, then goes back to waiting on the signal (see image). &amp;nbsp;Because the above code can be called rapidly, between the query step and the signalEventReceived, the long-running workflow can go from waiting on the signal to being busy with other things. &amp;nbsp;I do synchronize in the Java code so that only one signal is sent at a time. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://connect.hyland.com/legacyfs/online/alfresco/12737_Eclipse.png" style="width: 620px; height: 416px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We have tried a combination of "asynchronous" settings on the workflow after the intermediate signal catching event (the "Classify Series" and "Log Message", before it loops back to wait for the next signal).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the events come slowly enough, the workflow returns to the signal catching event and all works well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt; How can I make sure the long-running workflow returns to waiting for the signal before the next signal needs to be sent?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Help?&lt;/P&gt;&lt;P&gt;-dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 Feb 2017 14:08:05 GMT</pubDate>
    <dc:creator>blezek</dc:creator>
    <dc:date>2017-02-17T14:08:05Z</dc:date>
    <item>
      <title>How to handle a race condition signaling an Execution</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12852#M5663</link>
      <description>Hi,&amp;nbsp; We start long-running workflows that wait for a signal. &amp;nbsp;When certain events happen, we signal the workflow by searching for the list of Executions waiting on the signal (and some other criteria). &amp;nbsp;This can lead to race conditions because the incoming events can come in short order. &amp;nbsp;Here is ex</description>
      <pubDate>Fri, 17 Feb 2017 14:08:05 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12852#M5663</guid>
      <dc:creator>blezek</dc:creator>
      <dc:date>2017-02-17T14:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle a race condition signaling an Execution</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12853#M5664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you have to change your design to decouple the signal send and receive logic.&lt;/P&gt;&lt;P&gt;Put the signals onto a queue and then have the receiver loop through each signal/message in it's own time. Before "stopping" at the next "signal" look to see if there is already a message on the queue and process it immediately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you describe is a very typical issue when the processing time for signals can exceed the interval between received signals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/tag/bp3/tg-p"&gt;&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2017 22:50:35 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12853#M5664</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-02-17T22:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle a race condition signaling an Execution</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12854#M5665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greg, &amp;nbsp;Yup, that's what I figured you'd say... &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; &amp;nbsp;We will document that signal are delivered "best effort" and that workflows should not depend on them being delivered. &amp;nbsp;The notification logic adds the new information into a workflow variable and continues. &amp;nbsp;That logic also locks to have a single thread, so we don't clobber the workflow variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks much,&lt;/P&gt;&lt;P&gt;-dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2017 13:28:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-handle-a-race-condition-signaling-an-execution/m-p/12854#M5665</guid>
      <dc:creator>blezek</dc:creator>
      <dc:date>2017-02-23T13:28:43Z</dc:date>
    </item>
  </channel>
</rss>

