| Auszug |
|---|
|
Nuclos disable rule execution selectively: ThreadLocal switch, avoid endless loops, try/finally, disable UpdateRule, BusinessObjectProvider.update. |
Language: Deutsch · English
Selectively disabling rule execution
Avoid endless loops: disable individual rules per context via ThreadLocal switches.
| Status |
|---|
| colour | Green |
|---|
| title | Updated: Jul 2026 |
|---|
|
| Status |
|---|
| colour | Grey |
|---|
| title | applies to Nuclos 4.2026.x |
|---|
|
Why disable rules selectively?
Sometimes you want to prevent certain rules (or parts of them) from running – typically when updating individual fields from within a rule, to avoid endless loops or performance problems. This is done with cross-rule ThreadLocal variables.
| Warnung |
|---|
|
Use with care – do not undermine the business logic of the rules. For simple cases prefer SaveFlags. |
1. A switch in the rule to be disabled
| Codeblock |
|---|
|
public class MyUpdateRule implements UpdateRule {
// ThreadLocal-Schalter, initial aktiv
public static final ThreadLocal<Boolean> ACTIVE =
ThreadLocal.withInitial(() -> Boolean.TRUE);
public void update(UpdateContext context) throws BusinessException {
if (ACTIVE.get()) {
// ... eigentliche Logik ...
}
}
} |
ThreadLocal variables only affect the current thread/user context – the rule is not disabled globally (unlike the rule's active flag).
2. Disabling from the updating rule
| Codeblock |
|---|
|
MyBusinessObject mbo = QueryProvider.getById(MyBusinessObject.class, id);
mbo.setMyField(value);
try {
MyUpdateRule.ACTIVE.set(Boolean.FALSE); // Regel deaktivieren
BusinessObjectProvider.update(mbo);
} finally {
MyUpdateRule.ACTIVE.set(Boolean.TRUE); // immer wieder aktivieren!
} |
| Tipp |
|---|
| title | Don't forget finally |
|---|
|
Always re-activate in the finally block so the switch is reliably reset even on error. |
Related pages
Server-side rules
Rule context.
Open →
SaveFlags
Alternative on save.
Open →