# What's the best practice to set camunda:Exclusive=true & camunda:asyncBefore="true"?

**URL:** <https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [November 9, 2019, 12:29pm UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137 "2019-11-09T12:29:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [November 9, 2019, 12:29pm UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/1 "2019-11-09T12:29:25Z")

</div>

I would like to configure **async behaviour** in _activities & parallel gateway_ to execute concurrently using `camunda:Exclusive & camunda:asyncBefore` properties.

[parallelgateway-async.bpmn](https://forum.camunda.io/uploads/short-url/w0oJ1q4Ys8qsEudav5KoIU4LpNq.bpmn) (6.1 KB)

**Below are the scenarios:**

 ![image](https://forum.camunda.io/uploads/default/original/2X/2/23766d26a62983e456532cc929fdcfa3056233e9.png)

1. **Fork GW:** When forking the execution flow is it necessary to mark the parallel gateway as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”**? Is these property required in fork gw if it has multiple incoming sequences?

2. **Task A & Task B:** Both activities are marked as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”** , with parallel gateway, both tasks will be executed in parallel or sequential? Note both tasks are **after parallel gateway** and both tasks are marked as **camunda:Exclusive=“true”**. What’s the expected behaviour in execution?

3. **Task A & Task B:** Do I need to set **camunda:Exclusive=“false”** in service tasks to achieve concurrency along with **camunda:asyncBefore=“true”**?

4. **Task A & Task B** : What will be the behaviour if **Task A(camunda:Exclusive=“true”)** and **Task A(camunda:Exclusive=“false”)**? In this case _parallel join gateway need to marked as camunda:Exclusive=“true”?_

5. **Join GW** : When synchronizing the executions from Task A & Task B, i have marked the parallel gateway as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”** to avoid Optimistic locking exception. What is the behaviour if the complete process definition is synchronous execution( **camunda:asyncBefore|After=“false”** ), will the optimistic locking exception will throw in the parallel join?

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [November 11, 2019, 7:29am UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/2 "2019-11-11T07:29:43Z")

</div>

Hi @aravindhrs,

regarding your questions, it sems that the missing information about the exclusive flag can be found here: [The Job Executor | docs.camunda.org](https://docs.camunda.org/manual/7.11/user-guide/process-engine/the-job-executor/#exclusive-jobs).

My opinon to your questions:

> [@aravindhrs](#):
>
> **Fork GW:** When forking the execution flow is it necessary to mark the parallel gateway as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”**? Is these property required in fork gw if it has multiple incoming sequences?

There is no need to set `asyncBefore` or `asyncAfter` on a forking parallel gateway. It just puts load on the job executor.

> [@aravindhrs](#):
>
> **Task A & Task B:** Both activities are marked as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”** , with parallel gateway, both tasks will be executed in parallel or sequential? Note both tasks are **after parallel gateway** and both tasks are marked as **camunda:Exclusive=“true”**. What’s the expected behaviour in execution?

The tasks will be picked up in separated job acquisitions. That may not be real sequential execution (depending on the job executor configuration and one job runs significantly longer than the other), but the jobs are started one after the other.

> [@aravindhrs](#):
>
> **Task A & Task B:** Do I need to set **camunda:Exclusive=“false”** in service tasks to achieve concurrency along with **camunda:asyncBefore=“true”**?

Yes. But if both services write the same process variable or they join without further `asyncAfter` on the tasks or `asyncBefore` on the joining gateway, you may run into an `OptimisticLockingException`.

> [@aravindhrs](#):
>
> **Task A & Task B** : What will be the behaviour if **Task A(camunda:Exclusive=“true”)** and **Task A(camunda:Exclusive=“false”)**? In this case _parallel join gateway need to marked as camunda:Exclusive=“true”?_

I would assume that it is the same having both marked as exclusive (in case of two parallel tasks). It may change if you have more than two tasks and more than one maked as `exclusive=false`

> [@aravindhrs](#):
>
> **Join GW** : When synchronizing the executions from Task A & Task B, i have marked the parallel gateway as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”** to avoid Optimistic locking exception. What is the behaviour if the complete process definition is synchronous execution( **camunda:asyncBefore|After=“false”** ), will the optimistic locking exception will throw in the parallel join?

No, as the state of the process is held in memeory and commited to the database at the end of the process instance, you won’t see a `OptimisticLockingException` but a sequential execution of the services.

Hope this helps, Ingo

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [November 11, 2019, 9:49am UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/3 "2019-11-11T09:49:40Z")

</div>

> [@Ingo\_Richtsmeier](#):
>
> It may change if you have more than two tasks and more than one maked as `exclusive=false`

@Ingo_Richtsmeier, Both Parallel Tasks are async continuations, then **Task A** is marked as **camunda:Exclusive=“true”** and **Task B** is marked as **camunda:Exclusive=“false”**.

_So in this scenario, tasks are executed in sequentially and the property **async:Before=true** is not required to set at parallel join gateway right?_

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [November 11, 2019, 10:38am UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/4 "2019-11-11T10:38:47Z")

</div>

> [@Ingo\_Richtsmeier](#):
>
> > **Task A & Task B:** Both activities are marked as **camunda:asyncBefore=“true” & camunda:Exclusive=“true”** , with parallel gateway, both tasks will be executed in parallel or sequential? Note both tasks are **after parallel gateway** and both tasks are marked as **camunda:Exclusive=“true”**. What’s the expected behaviour in execution?
> 
> The tasks will be picked up in separated job acquisitions. That may not be real sequential execution (depending on the job executor configuration and one job runs significantly longer than the other), but the jobs are started one after the other.

_I hope when we mark parallel tasks are **exclusive=true** , will be picked by the same thread but in different job acquisition. Is that correct?_

From the docs,

> An exclusive job cannot be performed at the same time as another exclusive job from the same process instance. Consider the process shown in the section above: if the jobs corresponding to the service tasks are treated as exclusive, the job executor will try to avoid that they are executed in parallel.

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [November 12, 2019, 12:36pm UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/5 "2019-11-12T12:36:38Z")

</div>

Hi @aravindhrs,

I don’t know the details exactly, but I would assume that each job acquisition starts a new thread eventally.

Even if the acquisition is always the same thread, the execution will be handed to a new thread from the pool.

Hope this helps, Ingo

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 12:01pm UTC](https://forum.camunda.io/t/whats-the-best-practice-to-set-camunda-exclusive-true-camunda-asyncbefore-true/16137/6 "2024-01-30T12:01:53Z")

</div>

Closed on January 30, 2024, 12:01pm UTC


