sharedCache.releaseMutex¶
Signature: sharedCache.releaseMutex(mutexId, namespace*, global*, persist*)
Returns: Boolean result - true if the mutex was successfully released
Release the mutex so it's available for others to obtain.
The scope from which the mutex is released is determined by the namespace and global parameters. When no namespace is specified, the mutex is released only from inside the channel in which the mutexId was claimed. When a namespace was specified at claim time, the mutex is released across all channels in the same zone. When global was set to true at claim time, the mutex is released across all zones.
Note
It's important to specify the same namespace/global valuesthat were used when obtaining the mutex.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | mutexId | a unique string that identifies the mutex to release | |
| String | namespace* | (optional) a unique string used to limit the scope of the mutex | null |
| Boolean | global* | (optional) specifies whether or not the mutex being released is stored in the global cache | false |
| Boolean | persist* | (optional) specifies whether or not the mutex being released is stored in the database | false |
Example¶
// Claim the mutex so only one message at a time runs the critical section.
if (sharedCache.getMutex("token-refresh", 15000, 50000)) {
try {
qie.debug("Holding the token-refresh mutex while doing exclusive work");
} finally {
// Always release the mutex in a finally block so it is freed even if the work throws.
// Specify the same namespace/global values that were used when the mutex was obtained.
sharedCache.releaseMutex("token-refresh");
}
}