locked
Caching / thread safe access for RuleSet or RuleEngine RRS feed

  • Question

  • Is it safe to cache and access RuleSets and RuleEngines from multiple threads? I've done tests and everything seems to work OK (no exceptions, rules seem to execute fine). I ask because it's about an order of magnitude difference to spawn a new RuleEngine for each execution versus sharing one among threads. (Even higher to create new RuleSets...)

    The docs have the standard "static = safe, instance = not safe" but I'm not sure if that's totally accurate... Any guidance for perf here would be helpful.


    Thanks!

    -Michael

    Wednesday, May 16, 2007 10:41 PM

Answers

  • You should be OK even if two threads are executing the RuleEngine instance simultaneously.
    Thursday, May 17, 2007 6:46 PM

All replies

  • I assume that you mean that a given thread executes a RuleEngine, returns it to the cache and then another thread picks up the RuleEngine and executes it, correct?  In other words, you are only trying to execute a given RuleEngine instance on a single thread at a single point in time?  There shouldn't be any issues with this approach.
    Thursday, May 17, 2007 4:12 PM
  • Well I tried both ways and I haven't been able to repro any problems (versus, say, using the RuleParser, where I definately get exceptions when used concurrently). I was hoping that the RuleEngine was secretly threadsafe so I wouldn't have to use locks or an object pool...

     

    -Michael

    Thursday, May 17, 2007 4:40 PM
  • You should be OK even if two threads are executing the RuleEngine instance simultaneously.
    Thursday, May 17, 2007 6:46 PM
  • Sweet, that's great to know!

    Thanks,

    -Michael

    Thursday, May 17, 2007 7:25 PM