Hi Edson,
On 7/12/07, Edson Tirelli <tirelli(a)post.com> wrote:
Is it possible for you to provide a test case capable of reproducing the
problem?
I've written a quick test case, which is attached. When numberOfThreads==1,
everything compiles okay. When numberOfThreads==100, I get function
compilation errors and CompileExceptions from mvel. Clearly there is
nothing shared between these threads as a new test class is created
per thread. If you synchronise the calls to addPackage() and
getPackage() using the class monitor i.e.
synchronized (DroolsLoadTest.class) {
builder.addPackage(packageDescr);
builder.getPackage();
}
then the problems go away. Hope this helps.
At the same time, I would suggest you to not follow such approach
in your
application. Compilation is an extremely heavy process and should not be
done for each request. The ideal approach is to pre-compile (for instance,
we have a contributed ant-task for that) and serialize your rulebase to your
database or filesystem, or at least, compile it only once and cache it at
runtime.
That's very sensible advice. Our situation is slightly different as
users are allowed to change the rules used by a running service, so we
need to reflect any changes when a new request comes in. We are
planning to apply caching if performance is an issue, but we were
trying to assess performance of application under load when this
thread safety issue arose.
Thanks for your help,
Dean.