I have a class DroolsRuleLocator that fetches rules from the database, compiles and hands me back the RuleBase. At this time I have just one rule file with a bunch of rules in them. I do not experience any issues when I execute that in a single thread. <br>
<br>But when I load test my application and the client is passing in the request that requires <b>lookup and compilation of the same rule source in my server concurrently but on different threads,</b> it appears that my application is dead locked trying to compile the rules. <br>
<br>Relevant Rule compilation code:<br> RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br> try {<br> // Rule is a simple java bean containing the rule text.<br> for (Rule rule : rules) {<br>
// ruleDefinition will contain the contents of the drl source.<br> String ruleDefinition = rule.getRuleText();<br> PackageBuilder builder = new PackageBuilder();<br><br> // Parse and compile in one step<br>
builder.addPackageFromDrl(new StringReader(ruleDefinition));<br> if (builder.hasErrors()) {<br> throw new RuntimeException("Unable to compile rule definition: "+ rule.getName());<br>
}<br><br> // Get the compiled package (which is serializable)<br> Package pkg = builder.getPackage();<br><br> // Add the package to the created rulebase (deploy the rule package).<br>
ruleBase.addPackage(pkg);<br> }<br> }<br><br>Remote attaching to the tomcat server and suspending the hanging threads shows the following trace.<br><font size="2"><font face="Arial">Daemon Thread [http-8080-58] (Suspended) <br>
owns: PhaseInterceptorChain (id=315) <br> waiting for: StandardClassLoader (id=244) <br> owned by: Daemon Thread [http-8080-62] (Running) <br> StandardClassLoader(ClassLoader).loadClass(String, boolean) line: not available <br>
StandardClassLoader(ClassLoader).loadClass(String) line: not available <br> WebappClassLoader.loadClass(String, boolean) line: 1349 <br> WebappClassLoader.loadClass(String) line: 1208 <br>
ParserContext.checkForDynamicImport(String) line: 121 <br> ParserContext.hasImport(String) line: 155 <br> ExpressionCompiler(AbstractParser).createPropertyToken(int, int) line: 893 <br>
ExpressionCompiler(AbstractParser).nextToken() line: 836 <br> ExpressionCompiler._compile() line: 80 <br> ExpressionCompiler.compile(ParserContext) line: 44 <br> MVELExprAnalyzer.analyzeExpression(RuleBuildContext, String, Set[], Map) line: 85 <br>
MVELDialect.analyzeExpression(RuleBuildContext, BaseDescr, Object, Map) line: 320 <br> MVELDialect.analyzeExpression(RuleBuildContext, BaseDescr, Object) line: 308 <br> MVELFromBuilder.build(RuleBuildContext, BaseDescr, Pattern) line: 71 <br>
MVELFromBuilder.build(RuleBuildContext, BaseDescr) line: 50 <br> PatternBuilder.build(RuleBuildContext, BaseDescr, Pattern) line: 172 <br> PatternBuilder.build(RuleBuildContext, BaseDescr) line: 87 <br>
GroupElementBuilder.build(RuleBuildContext, BaseDescr, Pattern) line: 69 <br> RuleBuilder.build(RuleBuildContext) line: 53 <br> PackageBuilder.addRule(RuleDescr) line: 446 <br>
PackageBuilder.addPackage(PackageDescr) line: 304 <br> PackageBuilder.addPackageFromDrl(Reader) line: 167 <br> DroolsRuleLocator.findRuleBase(long, String) line: 122 <br><br>Can someone clarify if this dead lock scenario is a possibility. Currently I am sychronizing on the method that compiles and returns the RuleBase to avoid this situation.<br>
<br>Thanks.<br>- Krishna<br></font></font><br>