[rules-users] Multi thread error

Pierre Paysant-Le Roux pierre.paysant_leroux at travelsoft.fr
Tue Jul 10 08:59:18 EDT 2007


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



More information about the rules-users mailing list