I think Florian Fischer wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > Hello, > > I am using Jess in a multithreaded environment... > I need to understand how Jess works in a multithreaded environment. > > Is the following description correct? > - One lock is on all the data (facts, rules, the state of the engine, > etc. ) . That means you can do asserts, retracts, deffacts, defrules > and such simultaneously in multiple threads without risk.
Yes. > - A second lock prevents multiple rules to be fired at the same time. >From separate threads, yes. run()/runUntilHalt() can only be executed in one thread at a time. > > Can I assume that no 2 threads will fire a rule at the same time? Yes. > While the RHS is being executed, can I assume no other rule will > even be considered for firing before the RHS executed, even if run() > is called in the meantime in the same thread or another thread? No. If you call run() reentrantly -- i.e., if a rule fires, and that code itself calls run() again, then another rule could fire during the firing of the first rule. The result is undefined. Don't do this. > Will run() be ignored if called from a Java method called from a rule > RHS? No, it won't be ignored. > I tend to do a run() after every update to any fact. But it might > well be that the said update was called from the RHS of a rule firing > during a run(). Will this cause problems? > Yes it will. Don't do that. This has nothing to do with thread safety, but with whether run() is reentrant. It's not. > If one thread is executing run() (and fires and executes rules) and a > second threads calls run(), will they both fire rules or will the first > thread to all the work? The second thread will block until run returns. If yes, will the second thread wait for the > first run() to complete, tu guarantees all rules have fired? > The second thread will block until run returns for any reason -- halt() was called, or you called run(N) and N rules have fired, or an exception halts the run, etc. > If one thread is executing run() (and fires and executes rules) and a > second threads does a deffact() or undeffact(), can the facts be updated > while a RHS is executing? There is no "deffact()" method, but based on your earlier statements I think you mean "definstance()". Can facts be updated while a rule is firing? Yes. Values bound on the LHS are copies from the facts that activate a rule before the rule fires, so if the fact changes while the rule is firing, the original bound values are used. > Or will the facts change between 2 rules > firing? Or will the second thread block until run() returns and all > rules have fired? No and no. --------------------------------------------------------- Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------