This task controls who can access a common task. This prevents multiple threads from running the task at the same time. It works similar to a semaphore in programming.
Configuration Pane parameters
The key parameters include:
| Parameter | Description |
| Name | Enter the name that appears on the task. |
| Lock | Enter the name of the Lock. This serves as an identifier for the lock. |
| Max Lock Time | Enter the time that the system will wait before the lock expires. Measured in seconds. |
| Advance Rule | Specify how to advance to the task. The default is All predecessors have completed. |
Configure a Lock task
To configure a Lock task:
- Drag the Lock task onto the Workflow Editor canvas to add it.
Find the Lock task in the Workflow Controls section of the Workflow toolbox. - Select the Lock task and select the Edit icon to edit the parameters in the Task Configuration pane.
- Fill in the required parameters.
- Inside the Lock subprocess, add tasks to place the lock around.
- Select OK to apply changes in the Task Configuration pane.
- Fill in the required parameters.
- Select Save to save the workflow.
- Make the same changes to the next workflow process. Use the same lock name in the process. The Lock name used ensures the code inside runs once and can't be called while it's already running.
- Select Play in the Workflow Editor toolbar to start the workflow.
The workflow process starts.
The process log shows when the lock is waiting and when it is acquired for each thread that executes the Lock subprocess.
For example, if there are two separate workflow processes calling the same Conversion calculation. Since these are separate processes, there's a possibility of calling the Conversion calculation simultaneously. This could result in duplicate or corrupted data.
In this case, create a Lock task to create a lock on a subprocess. The first thread to reach the gate is allowed into the subprocess, while all other threads are denied. When the first thread finishes the subprocess, the gate is opened, and the next thread can get the lock on the subprocess. The Run Conversion Calculation is moved into the subprocess with a Lock so that only one thread can access and run it at any given time.
Use this technique to ensure that certain parts of a workflow are protected and can only be run by one process at a time.
Use case
In this example, there are two separate workflow processes that call the same calculation: the Canada process and the USA process. Both call the Run Conversion calculation.
To prevent duplicate data or data corruption:
- Move the Calculation: Place the Run Conversion calculation inside a new subprocess.
- Add a Lock Task: Insert a Lock task at the start of the subprocess.
- Control Access: The Lock task acts as a gate. The first thread to reach the gate can enter the subprocess, while the other threads must wait.
- Release the Lock: Once the first thread completes the subprocess, the gate is opened, and the next thread can enter.
This ensures that only one thread runs the Run Conversion calculation at any given time.