Does a particular rule may run concurently?

I wonder if a rule can start running before it ends its execution. for example i have something like this:

rule "X"
when Item x changed then

if x changes more than once in 2s does the rule starts second execution before returning from sleep ? If yes, then do the ReenatrantLock help to guard against such behaviour ?

Yes and this is a major reason why Thread:sleep longer than a couple hundred milliseconds are strongly discouraged.

It can but I recommend only using it as a last resort. Better to write your rule so

  • it is unlikely to ever run two instances at the same time because the rule runs fast and the events do not occur that fast
  • it doesn’t matter if two instances of the rule are running at the same time
  • it can ignore triggers that happen while the rule is actively running

If your rule does use ReentrantLocks and takes a long time to run and is likely to have more than one instance triggered at the same time you are likely to run out of Rule threads and your rules will come to a hault.