<?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 Synchronization puzzle in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157903#M112047</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To understand why I decide to use a semaphore for async process launching You should use the whole post In other case you can read only question section.&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;&lt;EM&gt;Can I synchronously launch asynchronous subprocess?&lt;/EM&gt;&lt;SPAN&gt; I mean (see code below), if I release semaphore inside a asynchronous subprocess, can I stop for-loop till the async subprocess will be started?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-java line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;for (int i = 0; i &amp;lt; 10; i++) {&lt;BR /&gt;&amp;nbsp; semaphore.acquire();&lt;BR /&gt;&amp;nbsp; runtimeService.signalEventReceived(…); //Launch async subprocess, inside which I release the semaphore&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My worflow diagram:&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="http://s1023.photobucket.com/user/bahmatjuk/media/processdiagram_zps180927cd.png.html?sort=3&amp;amp;o=0" rel="nofollow noopener noreferrer"&gt;http://s1023.photobucket.com/user/bahmatjuk/media/processdiagram_zps180927cd.png.html?sort=3&amp;amp;o=0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;What I have&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Multiple &lt;/SPAN&gt;&lt;EM&gt;asynchronous&lt;/EM&gt;&lt;SPAN&gt; subprocesses that are started by signal.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I launch my subprocesses in for loop from &lt;/SPAN&gt;&lt;EM&gt;'B'&lt;/EM&gt;&lt;SPAN&gt; user task. &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;But each subprocess should contain variables with the same name.&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;. It's very importand, because when I start subprocesses in for-loop with &lt;/SPAN&gt;&lt;EM&gt;signalEventReceived&lt;/EM&gt;&lt;SPAN&gt; method I can write only to global context, and then rewrite them to local context. &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;It means that I should use some synchronization to ensure that the next subprocess won't rewrite global context before the previous copy variables to it own local context&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Synchronization:&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I achieve synchronization with help of semaphore:&lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;handler bean (outside of activiti process)&lt;/EM&gt;&lt;BR /&gt;&lt;PRE class="language-java line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;for (int intVar: intVarList) {&lt;BR /&gt;&amp;nbsp; semaphore.acquire(); //ACQUIRE SEMAPHORE&lt;BR /&gt;&amp;nbsp; Map&amp;lt;String, Object&amp;gt; globalVars = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt;&amp;nbsp; globalVars.put("var", intVar);&lt;BR /&gt;&amp;nbsp; runtimeService.signalEventReceived("launchCandidateSubprocess", mainProcessExecution.getId(), globalVars);&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;EM&gt;And then in each subprocess:&lt;/EM&gt;&lt;BR /&gt;&lt;PRE class="language-java line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;public class FirstSubprocessService implements JavaDelegate [&lt;BR /&gt;&amp;nbsp; @Override&lt;BR /&gt;&amp;nbsp; public void execute(delegateExecution execution) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //……&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Integer localVar = (Integer) execution.get("var");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execution.setVariableLocal("var", localVar);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; semaphore.release(); // RELEASE THE SAME SEMAPHORE&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;What a problem:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;I acquire semaphore in the main thread, but I have to release semaphore in async subprocess!&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt; Activiti doesn't run new async subprocess directly from runtimeService.signalEventReceived method. It means that 'ACQUIRE SEMAPHORE' line reaches before async subprocess is launched, as a result before it can release a semaphore&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;FAQ:&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Q1: Why not multiinstance?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A1: Because I don't know how many subprocesses should I start. I may want to start additional subprocesses in any moment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Q2: Are semaphores in handler and FirstSubprocessService the same?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A2: Yes. I manage this with help of SingletonSemaphorefactoryBean.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Oct 2013 14:37:39 GMT</pubDate>
    <dc:creator>fritz128</dc:creator>
    <dc:date>2013-10-03T14:37:39Z</dc:date>
    <item>
      <title>Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157903#M112047</link>
      <description>To understand why I decide to use a semaphore for async process launching You should use the whole post In other case you can read only question section.Question:Can I synchronously launch asynchronous subprocess? I mean (see code below), if I release semaphore inside a asynchronous subprocess, can</description>
      <pubDate>Thu, 03 Oct 2013 14:37:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157903#M112047</guid>
      <dc:creator>fritz128</dc:creator>
      <dc:date>2013-10-03T14:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157904#M112048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't think I understand it yet. If you want each sub process to have it's own scope of variables I would recommend to use a call activity. Is than an option for you?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Oct 2013 19:09:57 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157904#M112048</guid>
      <dc:creator>trademak</dc:creator>
      <dc:date>2013-10-03T19:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157905#M112049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As I understand I can't simultaneously launch multiple async callActivities from one user task. &lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;Question1&lt;/EM&gt;&lt;SPAN&gt; Can I?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;main point&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;And another question. I've already written a demo with the same Activiti/Spring configurations, the same workflow and the same way to call asynchronous subprocesses.&amp;nbsp; And it works! But the same doesn't work in my application! &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I debuged it and it appeares that in my app after &lt;/SPAN&gt;&lt;EM&gt;signalEventReceived&lt;/EM&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;STRONG&gt;doesn't invoke next method of java.lang.Thread class&lt;/STRONG&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;STRONG&gt;In my demo where all works fine it the proceeding of new async subprocess begins from those method.&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;java&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;@Override&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void run() {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (target != null) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; target.run();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;/java&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;Question2&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN&gt;How does &lt;/SPAN&gt;&lt;EM&gt;signalEventReceived&lt;/EM&gt;&lt;SPAN&gt; works. Does it directly invoke&amp;nbsp; Thread.run method??&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Oct 2013 21:12:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157905#M112049</guid>
      <dc:creator>fritz128</dc:creator>
      <dc:date>2013-10-03T21:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157906#M112050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;signavlEventReceived uses the current thread, ie the thread which calls that method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In case of async, it will hand it over to the job executor. Is the job executor running?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 08:33:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157906#M112050</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2013-10-04T08:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157907#M112051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;EM&gt;How can I check if the JobExecutor is running?&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN&gt;I've set the next option &lt;/SPAN&gt;&lt;EM&gt;property name="jobExecutorActivate" value="true"&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN&gt;As I mentioned above, in case when it doesn't work it doesn't invole &lt;/SPAN&gt;&lt;EM&gt;Thread.run&lt;/EM&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;EM&gt;ExecuteJobRunnable.run&lt;/EM&gt;&lt;SPAN&gt; methods!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;What is VERY STRANGE:&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I've the same code in two places of my application: in first it works, in the second it doesn't!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first (works fine):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;java&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;runMainProcess();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i = 0; i &amp;lt; 10; i++)&amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; SemaphoreWrapper.acquire();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; runtimeService.signalEventReceived("signal", executionId);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;/java&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But if to move for-loop and runMainProcess() to two different requests it DOESN'T work. I've checked in debug: executionId, commandExecutor and all other parameters are the same!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;In which cases Activiti doesn't run new async subprocess before next cycle of for-loop?&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 10:39:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157907#M112051</guid>
      <dc:creator>fritz128</dc:creator>
      <dc:date>2013-10-04T10:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Synchronization puzzle</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157908#M112052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That sounds very very weird … can't really explain why the exact code does two different things dependending on the setup.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 09:55:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/synchronization-puzzle/m-p/157908#M112052</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2013-10-21T09:55:12Z</dc:date>
    </item>
  </channel>
</rss>

