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@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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users