Question about rule execution

Hello,

I was wondering of rules are executed together or that each rule is executed one after another.

They are executed in parallel up to a point. There is a limited number of rules that can execute at the same time. When that limit is reached new rules must wait for old ones to exit.

Is have made some rule with a “flag” variable in it.
while that rule is running the “flag” = 1.
In another rule I use that “flag” (using a if function) to prevent some item updates.
But the update do occur so that is wy I was wondering how the rule execution order happens.

If you want to prevent another rule from running while one is running, or more commonly prevent more than one instance of a given rule from running at a given time, it is best to use a ReentrantLock (search the forum for examples).

Have you ever used ReentrantReadWriteLock ? SUPPOSEDLY can yield separate Read (non-blocking, essentially) and Write (blocking–DUH) sub-locks…I have not been able to get it to resolve in OH2, but it might be dementia on my part…:slight_smile:

I’ve used them, or at least something like them in other languages. I’m not sure I’ve used them in Java. I usually go to great lengths to avoid locks at all costs, even to the point I’ll come up with an entirely different approach it architecture.