[id='rule-base-configuration-con_{context}']

= Rule base configuration

{PRODUCT} contains a `RuleBaseConfiguration.java` object that you can use to configure exception handler settings, multithreaded execution, and sequential mode in the {RULE_ENGINE}.

For the rule base configuration options,
ifdef::DM,PAM[]
download the *{PRODUCT} {PRODUCT_VERSION_LONG} Source Distribution* ZIP file from the https://access.redhat.com/jbossnetwork/restricted/listSoftware.html[Red Hat Customer Portal] and navigate to `~/{PRODUCT_FILE}-sources/src/drools-$VERSION/drools-core/src/main/java/org/drools/core/RuleBaseConfiguration.java`.
endif::[]
ifdef::DROOLS,JBPM,OP[]
see the {PRODUCT} https://github.com/kiegroup/drools/blob/{COMMUNITY_VERSION_BRANCH}/drools-core/src/main/java/org/drools/core/RuleBaseConfiguration.java[RuleBaseConfiguration.java] page in GitHub.
endif::[]

The following rule base configuration options are available for the {RULE_ENGINE}:

drools.consequenceExceptionHandler::
When configured, this system property defines the class that manages the exceptions thrown by rule consequences. You can use this property to specify a custom exception handler for rule evaluation in the {RULE_ENGINE}.
+
--
Default value: `org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler`

You can specify the custom exception handler using one of the following options:

* Specify the exception handler in a system property:
+
[source]
----
drools.consequenceExceptionHandler=org.drools.core.runtime.rule.impl.MyCustomConsequenceExceptionHandler
----

* Specify the exception handler while creating the KIE base programmatically:
+
[source,java]
----
KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration(); kieBaseConf.setOption(ConsequenceExceptionHandlerOption.get(MyCustomConsequenceExceptionHandler.class));
KieBase kieBase = kieContainer.newKieBase(kieBaseConf);
----
--

drools.multithreadEvaluation::
When enabled, this system property enables the {RULE_ENGINE} to evaluate rules in parallel by dividing the Phreak rule network into independent partitions. You can use this property to increase the speed of rule evaluation for specific rule bases.
+
--
Default value: `false`

You can enable multithreaded evaluation using one of the following options:

* Enable the multithreaded evaluation system property:
+
[source]
----
drools.multithreadEvaluation=true
----

* Enable multithreaded evaluation while creating the KIE base programmatically:
+
[source,java]
----
KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();
kieBaseConf.setOption(MultithreadEvaluationOption.YES);
KieBase kieBase = kieContainer.newKieBase(kieBaseConf);
----

[WARNING]
====
Rules that use queries, salience, or agenda groups are currently not supported by the parallel {RULE_ENGINE}. If these rule elements are present in the KIE base, the compiler emits a warning and automatically switches back to single-threaded evaluation. However, in some cases, the {RULE_ENGINE} might not detect the unsupported rule elements and rules might be evaluated incorrectly. For example, the {RULE_ENGINE} might not detect when rules rely on implicit salience given by rule ordering inside the DRL file, resulting in incorrect evaluation due to the unsupported salience attribute.
====
--

drools.sequential::
When enabled, this system property enables sequential mode in the {RULE_ENGINE}. In sequential mode, the {RULE_ENGINE} evaluates rules one time in the order that they are listed in the {RULE_ENGINE} agenda without regard to changes in the working memory. This means that the {RULE_ENGINE} ignores any `insert`, `modify`, or `update` statements in rules and executes rules in a single sequence. As a result, rule execution may be faster in sequential mode, but important updates may not be applied to your rules. You can use this property if you use stateless KIE sessions and you do not want the execution of rules to influence subsequent rules in the agenda. Sequential mode applies to stateless KIE sessions only.
+
--
Default value: `false`

You can enable sequential mode using one of the following options:

* Enable the sequential mode system property:
+
[source]
----
drools.sequential=true
----

* Enable sequential mode while creating the KIE base programmatically:
+
[source,java]
----
KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();
kieBaseConf.setOption(SequentialOption.YES);
KieBase kieBase = kieContainer.newKieBase(kieBaseConf);
----

* Enable sequential mode in the KIE module descriptor file (`kmodule.xml`) for a specific {PRODUCT} project:
+
[source,xml]
----
<kmodule>
  ...
  <kbase name="KBase2" default="false" sequential="true" packages="org.domain.pkg2, org.domain.pkg3" includes="KBase1">
    ...
  </kbase>
  ...
</kmodule>
----
--
