We want to use Drools to do a delay job. So, I use timer(int:5s) to do that. However, after I inserted an fact object to the KieSession, the KieSession will start a separated "Thread-XX" to dealt with this delay job, but this thread will never end although the rule has been executed after 5s elapsed.
As a result, if I inserted a large number fact object, for example 100000 objects, there will be 100000 threads in this KieSession, the memory will raise to about 500MB and it will never drop down. The more inserts, the more memory consumed.
I think Drools should close those threads if the object has been evaluated and executed the rule since they're useless.
Is there some option to make those timer thread shutdown after executed? I know drools.halt() in drl file, however, it will halt the whole session rather than each thread in this KieSession.
Here are my code:
1.main class
KieServices ks = KieServices.Factory.get();
final KieContainer kContainer = ks.getKieClasspathContainer();
final KieSessionConfiguration ksconf = ks.newKieSessionConfiguration();
ksconf.setOption(TimedRuleExectionOption.YES);
final KieSession kSession = kContainer.newKieSession("ksession-rules", ksconf);
for (int i = 0; i < 100000; i++) {
Thread t1 = new Thread(new Runnable() {
public void run() {
Message message = new Message();
message.setStatus(Message.HELLO);
kSession.insert(message);
kSession.fireUntilHalt();
}
});
t1.start();
}
drl file
dialect "mvel" rule "Hello World" timer(int:10s) when m : Message(m.status == Message.HELLO) then System.out.println( "no hello"+m.message ); end
The code above is to share a KieSession. I also try to use one KieSession per fact and then halt and dispose it. However, 100000 KieSession reside in memory at same time will cause 6.7GB memory usage. It's also not acceptable.
So, anyone can help me?
Actually, my business logic is to check if the control point and feedback point are the same within 5mins, otherwise sound an alarm. And there will be about 100000 request at same time. So, is there some other better way to achieve this case by Drools?
Thanks,


Thread t1 = new Thread(...inside the for loop. - tarilabs