vRO A Better lockAndWait Solution - LockAndSteal

This action is a lock and wait for the specified wait time (in seconds)
If one owner keeps the lock beyond the specified wait time the lock is removed and the action tries to obtain the lock

The vRO locking system provides a method called "lockAndWait" that you can use to create single threaded code. For example, you may have logic that requires you to interface with external systems that can not handle more than one request at a time, so you have to make the interface code single threaded to eliminate race conditions.

One problem with the native "lockAndWait", however, is when a failure occurs in the locked code segment. If the failure is caused by an external system the lock may never be "unlocked", and any future execution of the "lockAndWait" will end up in an infinite wait, never proceeding through the code and causing cascade failures throughout your process.

That's why I created the action called "lockAndSteal". It is equivalent to lockAndWait, but with the ability to provide a timeout value. You can use lockAndSteal anywhere you currently use lockAndWait.

LocakAndSteal uses the native vRO locking system methods, but not lockAndWait, to obtain and hold a system lock for a code segment. If another execution instance tries to obtain a lock using the same id lockAndSteal will wait for the given timeout period, and if still not released, will release the lock and obtain a new one for the waiting instance.

You can of course extend lockAndSteal to include any number of failure recovery mechanisms, including a call to send an email on any "steal" so that the appropriate action can be taken for possible external issues, if the single thread code happens to have external calls.

 


Sign in to be able to add comments.

Comments 0