Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions concepts/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ openHAB can send a notification to your phone.
Other systems may have a concept of _Automations_, _Tasks_, and other terms.
In openHAB, rules are used to implement all of these concepts.

Rules can be executed, either when fired by their triggers, or when called explicitly – from a script, another rule, a Main UI widget, etc.
When a rule is fired by its trigger, the execution of one and the same rule does not happen in parallel.
If a rule is triggered for execution, while the rule is currently running, it will be queued and run later.

When a rule is called explicitly - e.g. from a script, another rule with [`RuleManager.runNow()`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/rulemanager), or from a Main UI widget - then this rule can be executed in parallel.
Comment thread
florian-h05 marked this conversation as resolved.
That is it can start running, while the same rule is executed at the same time.
In this case there is a need to program protection against race conditions.

## Parts of a Rule

These rules take the high level form of _When \_\_t\_\_ happens, if \_\_c\_\_ then do \_\_a\_\__,
Expand Down
3 changes: 2 additions & 1 deletion configuration/rules-dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,8 @@ Caveat: Please note the semicolon after the return statement which terminates th

### Concurrency Guard

If a rule triggers on UI events it may be necessary to guard against concurrency.
If a rule is explicitly run from another script, rule, a Main UI widget, etc., instead of a trigger, the rule can be started before the current execution has ended.
It may be necessary to guard against concurrency.

```javascript
import java.util.concurrent.locks.ReentrantLock
Expand Down