<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Is there a way to use some kind of semaphore in ivy?</title><link>https://answers.axonivy.com/questions/2184/is-there-a-way-to-use-some-kind-of-semaphore-in-ivy</link><description>&lt;p&gt;I have the situation that I have a database call which gives me a list of elements. Some activities later I write down the modified elements to the db. This is working fine als long as I don't have parallelism. The problem is that the second db operation potentially affects the first db operation. If now two tasks arrive at the first element and read from the database before one task has written the result to the db I get a wrong result. The solution would be to prevent the second task entering the first database read until the first task has written down the result.&lt;/p&gt;
&lt;p&gt;Do we have some kind of support for such cases?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2184/is-there-a-way-to-use-some-kind-of-semaphore-in-ivy" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 16 Nov 2016 13:03:18 -0500</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/2184/is-there-a-way-to-use-some-kind-of-semaphore-in-ivy/2191</link><description>&lt;p&gt;You could encapsulate the relevant DB steps in a SubProcess. Instead of calling the SubProcess directly you could delegate that to a Java method with 'synchronized' modifier. &lt;/p&gt;
&lt;p&gt;To call a SubProcess from Java just use the SubProcessCall API: &lt;a href="http://developer.axonivy.com/doc/latest/publicApi/ch/ivyteam/ivy/process/call/SubProcessCall.html"&gt;http://developer.axonivy.com/doc/latest/publicApi/ch/ivyteam/ivy/process/call/SubProcessCall.html&lt;/a&gt;
Or if you not on the leading edge train: use the elder SubProcessRunner API: &lt;a href="http://developer.axonivy.com/doc/latest/publicApi/ch/ivyteam/ivy/process/call/SubProcessRunner.html"&gt;http://developer.axonivy.com/doc/latest/publicApi/ch/ivyteam/ivy/process/call/SubProcessRunner.html&lt;/a&gt; &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Wed, 16 Nov 2016 13:03:18 -0500</pubDate><guid>https://answers.axonivy.com/questions/2184/is-there-a-way-to-use-some-kind-of-semaphore-in-ivy/2191</guid></item></channel></rss>