Yes, indeed. executeCommand() can only be executing one command at a
time, so multiple threads will exclude one another (not a deadlock at
all; the requests are just "serialized", or done one at a time.)
assertString() does share a mutex with executeCommand, so only one of
the two may be executing at once on any one Rete object.
Your workaround is not terrible, but there are others. If you're going
to drive everything from Java code, then you shouldn't use
executeCommand() and assertString() at all, really; they are just
there to make life easier for people who are running one or two
commands. Note that the Rete class has a number of public methods to
make driving programs easier: run(), reset(), halt(), and assert(),
for example. Using these is considerably more efficient than creating
Funcalls to run the equivalent Jess language commands, and much more
efficient than using executeCommand to parse a String, which will then
create a Funcall, which will then call the methods on the Rete class!
For things which don't have an equivalent method in Rete, then
Funcalls are the way to go.
By the way, the manual explains how to build Fact objects pretty
clearly, I thought; see section 4.7.
I think Richendra Khanna wrote:
>
>
> I think I ran into exactly this problem yesterday.
> I'll describe what I was doing.
>
> I have a thread in which I batch load my rules script, and then run it.
> This is my main rete thread.
>
> rete.executeCommand("(batch xxx.clp)");
> rete.executeCommand("(reset)");
> rete.executeCommand("(run)");
>
> In another thread from my java code I get the rete instance, and
> call assertString to put in some stuff which would fire some rules.
>
> rete.assertString("(justdoit)");
>
> This doesn't work. Doing this in the rules script works.
>
> The problem, I realized, was because in assertString() the engine
> tries to lock m_tis to parse the facts. This however will block
> because the (run) in the main thread would already have locked it.
> So it's a deadlock situation.
>
> The way I found around this was to use Funcall to do assert.
>
> Funcall f = new Funcall("assert", rete);
> f.add(new Value(new Fact("justdoit", rete), RU.FACT));
> f.execute(rete.getGlobalContext());
>
> This doesn't try to acquire a lock on m_tis since you're already
> parsing the fact yourself to create the Fact object.
> Of course I'm not sure how you'd do it for a complicated fact,
> didn't decipher the parseFact code that far.
>
> It is working for me, of course that doesn't mean I'm right.
>
> Richendra.
>
> Ernest Friedman-Hill wrote:
> >
> > The most likely explanation is that assertString() is
> > throwing an exception that is being ignored in your code. Never write
> > Java catch blocks that look like
> >
> > catch (JessException je) {}
> >
> > Always at least include a print statement in the catch block!
> >
> > If this isn't it, though, show me the -smallest possible, complete
> > example- the reproduces the problem and we'll go from there.
> >
> >
> > I think [EMAIL PROTECTED] wrote:
> > >
> > >
> > > Hello Jess Users;
> > >
> > > I have written rules in *.clp file. In this file some rules are fired,
> > >
> > > after an assertion is done from Java.
> > > I have used assertString method defined in Rete.java in
> > > myprogram.java.
> > > But this assert statement is not asserting the fact, and hence
> > > subsequent
> > > rules are not fired.
> > >
> > > Any body can help me how to solve this problem.
> > >
> > > If I assert initially in *.clp file, then my rules are working fine.
> > >
> > > Thank you
> > > RagJag
> > >
> >
>
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------