Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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, MainUI widget.
Comment thread
florian-h05 marked this conversation as resolved.
Outdated
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 - from a script, another rule with [`RuleManager.runNow()`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/rulemanager), from a MainUI widget, then this rule can be executed in parallel.
Comment thread
florian-h05 marked this conversation as resolved.
Outdated
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, MainUI widget, instead of a trigger, the rule can be started before the current execution has ended.
Comment thread
florian-h05 marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a rule is explicitly run from another script, rule, MainUI widget, instead of a trigger, the rule can be started before the current execution has ended.
If a rule is explicitly run from another script, rule, a Main UI widget, 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