Rules cycling despite reentrant.lock

Posting for future ref - It seems the solution here is to use a structure like

boolean gotLock = lock.tryLock();
try{
    if(gotLock){
        // Do Stuff
    } else {
        // Don't do stuff
    }
}
finally{
    if(gotLock){
        lock.unlock();
    }
}

The .tryLock method allows for acquiring and testing the lock all in one go. It will grab the lock and return TRUE, or it will fail to get the lock and return FALSE. Then you can make a decision, in Nathan’s case to abort the rule altogether, and are not forced into a queue as with the simple .lock method.

By putting a sleep in the got-lock code, you can reject subsequent triggers for a period while it has possession of the lock. An effective (if complicated) debounce method.

1 Like