Hello,
My question is:
How can I ensure that a nested property isn't null (in a multithreaded
environment)?
This is the rule:
rule "Drools Test3: Concurrency"
dialect "java"
when
$testObj : TestObject(
$ref : subObject,
$ref != null,
$ref.message != null
)
then
System.out.println("Received-04-A: " + $testObj);
end
I am getting the following exception if I try to modify the fact in
different threads.
java.lang.NullPointerException: null
at
ConditionEvaluator8d1e3555e8c34810957bbb1670f51176.evaluate(null:-1)
at
org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
at
org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
at
org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at
org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:976)
at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:949)
at
org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:284)
[...]
There are two threads running which modify the same reference in a
testobject ("subObject"). They trigger a queued update of the fact.
One solution would be:
- insert the nested object in drools
- and modify the rule:
rule "Drools Test3: Concurrency 2"
dialect "java"
when
$subObj : TestObject(
message != null
)
$testObj : TestObject(
subObject == $subObj
)
then
System.out.println("Received-04-A: " + $testObj);
end
Can I achieve a thread safety differently?
Thanks and regards,
Per Sterner
Show replies by date