Lock workflow activity

The Lock activity prevents other instances of this workflow from continuing past this activity until the lock is released.

Several instances of the same workflow may run concurrently. For example, if a workflow is triggered when a record is added to a particular table and multiple records are added one after the other, that workflow will be triggered multiple times: once by each record insertion. In such cases, you can use the lock activity to ensure that this instance of the workflow has completely finished one or more activities before any other instance of the workflow can proceed.

A workflow can explicitly release a lock with the Unlock activity. The lock may also be released when the Max duration is reached.

When an instance of the workflow reaches the Lock activity, it attempts to obtain a lock using the key specified in the lock activity. If another instance has already obtained the lock and has not yet released it, this lock attempt fails. The instance continues trying to obtain the lock until Max attempts has been reached.


We recommend placing a one-second timer activity before the lock activity. This helps prevent a rare condition in which the lock activity may not be able to distinguish one workflow instance from another. This condition can occur because the entity owning the lock is not the specific workflow instance, but rather the code-execution thread in which that instance is running. In most cases, each workflow instance runs on a different thread, but adding a timer activity ensures that this is the case.

Figure 1. Example of Lock Activity Preceded by Timer Activity
Screenshot of workflow with timer activity before lock activity


Table 1. Lock activity results
Result Description
Success The activity successfully obtained a lock. This instance of the workflow can proceed past this point, but other instances cannot until the lock is released.
Failure After attempting to obtain the lock Max attempts times, the activity could not obtain the lock.

Input variables

Input variables determine the initial behavior of the activity.

Table 2. Lock activity input variables
Field Description
Key A unique mutex key. The Unlock activity activity uses this key to release the lock.
Max. duration The maximum time the lock persists. The lock is released after it reaches this duration. Releasing a lock this way is equivalent to running the Unlock activity.
Lock attempts

Specify how the activity behaves if the lock attempt is denied. If the final lock attempt fails, the activity state will be set to 'timeout' and the activity result will be set to 'failed'.

Max. attempts Specify the maximum number of times the activity may attempt to obtain the lock.
Delay between attempts The amount of time required after a failed lock attempt before another lock attempt is allowed.


The activity state tells the workflow engine what to do with the activity.

Table 3. Lock activity states
State Description
Waiting The workflow engine is waiting to obtain a lock.
Finished The activity successfully obtained the lock.
Timeout The activity could not obtain a lock within the number of attempts specified by the Max. attempts input variable.