[rules-users] OutOfMemoryError happens when dynamic loading of Rules from Guvnor frequently
Oliver Liu
liuyy2000 at hotmail.com
Wed Jun 22 21:41:03 EDT 2011
I read the source code of org.drools.agent.impl.KnowledgeAgentImpl, in this
segment
private void rebuildResources(ChangeSetState changeSetState) {
...
/*
* Rebuild a new knowledge base. Try to use the old configuration if
* possible
*/
if (this.kbase != null) {
this.kbase =
KnowledgeBaseFactory.newKnowledgeBase(((InternalRuleBase)
((KnowledgeBaseImpl) this.kbase).ruleBase).getConfiguration());
} else {
this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
}
...
}
Before giving a new value to this.kbase, i think maybe we should release
resource in it, so i tried to change code like this:
[6/21/2011 12:34:16 PM] liuyy_skype: if (this.kbase != null) {
for(KnowledgePackage packs : this.kbase.getKnowledgePackages())
{
KnowledgePackageImp kpkg = ((KnowledgePackageImp)packs);
for (Rule rule : kpkg.pkg.getRules()) {
removeKnowledgeDefinitionFromBase(rule);
}
for (Process process : kpkg.pkg.getRuleFlows().values()) {
removeKnowledgeDefinitionFromBase(process);
}
for (Function function : kpkg.pkg.getFunctions().values()) {
removeKnowledgeDefinitionFromBase(function);
}
for (TypeDeclaration dec :
kpkg.pkg.getTypeDeclarations().values()) {
removeKnowledgeDefinitionFromBase(dec);
}
this.kbase.removeKnowledgePackage(kpkg.getName());
kpkg.pkg.clear();
Runtime.getRuntime().gc();
}
this.kbase =
KnowledgeBaseFactory.newKnowledgeBase(((InternalRuleBase)
((KnowledgeBaseImpl) this.kbase).ruleBase).getConfiguration());
} else {
this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
}
Then i run my code, the memory indeed increased not so much like before, but
still rise. though the added code work, but i think there are some risk in
it, e.g. if the app are using a session which created from kbase, this code
may cause exception.
Any idea?
Thanks
Oliver
--
View this message in context: http://drools.46999.n3.nabble.com/OutOfMemoryError-happens-when-dynamic-loading-of-Rules-from-Guvnor-frequently-tp3079965p3098144.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list