[rules-users] Multi thread error
Ronald R. DiFrango
ron.difrango at gmail.com
Wed Jul 11 13:13:50 EDT 2007
Pierre,
There is no need to rebuild the entire rules base with each thread. You can
build the rule base statically at startup. Then within your thread's just
do:
// Note this is 4.0 syntax:
final StatefulSession session = ruleBase.newStatefulSession();
A single working memory is thread safe and the call in the ruleBase to
create it is as well.
Ron
On 7/10/07, Pierre Paysant-Le Roux <pierre.paysant_leroux at travelsoft.fr>
wrote:
>
> Hi,
> I have a problem using Drools in a multi thread program. I want that
> several threads use there own working memory. There is an error when two
> thread are building the same PackageBuilder at the same time. The
> exception is: java.lang.LinkageError: duplicate class definition.
>
> Here is a simple program that generates the error.
>
> package com.sample;
>
> import java.io.IOException;
> import java.io.InputStreamReader;
>
> import org.drools.compiler.DroolsParserException;
> import org.drools.compiler.PackageBuilder;
> import org.drools.compiler.PackageBuilderConfiguration;
>
> public class TestThreads {
>
> public static void main(String[] args) {
> for(int i = 0; i<2 ; i++) {
> DroolsThread tt = new DroolsThread();
> tt.start();
> }
> }
>
> public static class DroolsThread extends Thread {
>
> public void run() {
> PackageBuilderConfiguration pkgBuilderCfg =
> new PackageBuilderConfiguration();
> PackageBuilder builder = new PackageBuilder(pkgBuilderCfg);
> try {
> builder.addPackageFromDrl(new
> InputStreamReader(DroolsTest.class.getResourceAsStream( "/Sample.drl" )));
> } catch (DroolsParserException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
> }
>
>
> I don't understand what to do to avoid the exception : using
> "synchronized" somewhere ? Can someone help me please ?
> Thanks
> Pierre
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070711/5c8cf8f2/attachment.html
More information about the rules-users
mailing list