Hi Davide,
you were right. The import functions I defined were copied from another Project, which is
not linked to my current Project. So the packages of the function classes did not exists
in my Path. After I moved the function classes and changed the package declarations it
worked.
Thank you very much.
Bojan
----- Ursprüngliche Mail -----
Von: "Davide Sottara" <dsotty(a)gmail.com>
An: rules-users(a)lists.jboss.org
Gesendet: Freitag, 31. Mai 2013 11:54:42
Betreff: Re: [rules-users] NullpointerException in Multithreading at KnowledgeBuilde
The error has nothing to do with the multiple threads.
There is a small bug in MVELDialect: the "import function" probably
fails and a compilation error would be returned,
but the code tries to use the supposedly imported and resolved class anyway.
I'll open a JIRA.
Thanks
Davide
On 05/31/2013 11:30 AM, Bojan Janisch wrote:
Hi everyone,
I'm using Drools in a multithreaded environment where I need to create multiple
KnowledgeBuilders, which each contains a different rule. But if I want to add the rule to
the builder I'm getting the following exception:
-----------------------------------------------------------------------
Exception in thread "ECJ Evaluation Thread 3" java.lang.NullPointerException
at
org.drools.rule.builder.dialect.mvel.MVELDialect.addStaticPackageImport(MVELDialect.java:416)
at
org.drools.rule.builder.dialect.mvel.MVELDialect.addStaticImport(MVELDialect.java:372)
at
org.drools.compiler.DialectCompiletimeRegistry.addStaticImport(DialectCompiletimeRegistry.java:96)
at org.drools.compiler.PackageRegistry.addStaticImport(PackageRegistry.java:94)
at org.drools.compiler.PackageBuilder.processFunctions(PackageBuilder.java:1270)
at
org.drools.compiler.PackageBuilder.processOtherDeclarations(PackageBuilder.java:1225)
at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:1220)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:829)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at rulevolution.RulEvolution.getSession(RulEvolution.java:195)
at rulevolution.RulEvolution.runDrools(RulEvolution.java:159)
at rulevolution.RulEvolution.evaluate(RulEvolution.java:106)
at ec.simple.SimpleEvaluator.evalPopChunk(SimpleEvaluator.java:259)
at ec.simple.SimpleEvaluator$SimpleEvaluatorThreadCG.run(SimpleEvaluator.java:341)
at ec.util.ThreadPool$PoolThread.run(ThreadPool.java:57)
-----------------------------------------------------------------------
I'm getting the same exception in each thread so I only copied thread 3.
The Code I'm using to initiate my Session is the following:
-----------------------------------------------------------------------
public synchronized StatefulKnowledgeSession getSession(byte[] array){
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(array), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (!errors.isEmpty()) {
for (KnowledgeBuilderError knowledgeBuilderError : errors) {
logger.log(Level.SEVERE, "error while parsing grammmars in
"+knowledgeBuilderError.getResource().toString()+":: "
+ knowledgeBuilderError.getMessage());
}
try {
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
}
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase.newStatefulKnowledgeSession();
}
-----------------------------------------------------------------------
This method is called for each Rule I create one time. The rules are created
automatically and are syntactically correct, here is an example:
-----------------------------------------------------------------------
import function de.fraunhofer.scai.bio.uima.droolutils.FactChecker.*;
import function de.fraunhofer.scai.bio.uima.droolutils.ODMAnswerManager.*;
global org.apache.uima.util.impl.JSR47Logger_impl log
global org.apache.uima.jcas.JCas aJCas
rule '2'
when
$0: CoreAnnotation(
label_0:getActivityProvenance().toString(),
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.bodySide'))
$1: CoreAnnotation(
label_1:getActivityProvenance().toString(),
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.anatomy'))
$2: NormalizedNamedEntity(
label_2:getConcept().getPrefLabel().value,
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.anatomy'))
eval (hasSameInstance($0, $1, $2))
eval (areEqual($0, $1, $2))
then
int start = getStart($0,$1,$2);
int ende = getEnd($0,$1,$2);
String attribute = label_0+label_1+label_2;
log.log(Level.FINE, 'Inserted de.cloud4health.odm.eprd.itemGroup.anatomy');
insert(annotate(aJCas, 'de.cloud4health.odm.eprd.itemGroup.anatomy', attribute,
start, ende, null, null));
end
-----------------------------------------------------------------------
I appreciate any help. Thank you.
Bojan
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org