[rules-users] how do RuleBase.lock()/unlock() functions work?

Marina ppine7 at yahoo.com
Fri Aug 22 15:42:01 EDT 2008


Hello!

I am researching how to do thread safe update of packages/rules in a rulebase. I noticed that there are lock() and unlock() methods on the RuleBase object, but could not find much documentation on how they could be used.
I am trying to implement the following scenario and was wondering if someone could verify that I am using the lock functionality correctly in this case:

Thread1:
1. rulebase.getStatelessSession()
1.1 rulebase.lock()
1.2 rulebase.removeRule(rule1)
1.3 rulebase.removePackage(somePackage)
1.4 rulebase.addPackage(someCompiledNewPackage)
1.5 rulebase.unlock()

Thread2
2. rulebase.getStatelessSession()

Threads 1 and 2 use the same rulebase object.
Quesion 1: What does it mean having the rulebase be locked in Thread1? Does it mean, that if Thread2 is trying to get the session , say, between steps1.2 and 1.3 of the Thread1 , then it will wait until Thread1 released the lock on the rulebase?

If that's true, that's exactly what I need.

Question 2: I also see methods rulebase.getAdditionsSinceLock() and getRemovalsSinceLock(). Who will see anything when calling these functions - Thread1 after operation 1.5? before 1.5? 
Or Thread2? But, which lock would it mean to Thread2? - it woudl probably not even be aware of any locks being place by other threads??

Thanks!
Marina



More information about the rules-users mailing list