[rules-users] How to pre compile rule files for production

abhilashkumar at amritatech.com abhilashkumar at amritatech.com
Sat Apr 14 09:44:15 EDT 2007


Hello,

  I am using 3.0 RC 2 version of DROOLS in one of our project. (JDK 1.4.2
and JBoss 3.2.7) When we deployed the application into production, we
are facing performance issues that seems to be because of class loading
and GC collection of rule classes that are created at runtime. So I went
back to the docs and wiki and decided to try the pre-compile and caching
options. Eventhough i searched the wiki, mailing list archives and doc,
i was not able to find any advice on how can I do this. Ours is a J2EE
application and the EJBs call a static method in an helper class which
will laod the .drl file, build the PackageBuilder and Rulebase, create
the WorkingMemory and execute the rule.

  Any pointers on how to pre compile the rule and then execute it will be
really helpful. Below is the current code that executes the rule.

Thanks and Regards,

-- Abhilash.


private static RuleResultVO execute( String ruleFile, Object [] objects )
throws AppException {


		RuleResultVO ruleResult = new RuleResultVO();
		try {

	        //read in the source
		InputStream in = ResourceLoader.getResourceAsStream(ruleFile);
	        Reader reader = new InputStreamReader(in);
	        DrlParser parser = new DrlParser();
	        PackageDescr packageDescr = parser.parse( reader );

	        //pre build the package
	        PackageBuilder builder = new PackageBuilder();
	        builder.addPackage( packageDescr );
	        Package pkg = builder.getPackage();

	        //add the package to a rulebase
	        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
	        ruleBase.addPackage( pkg );

	        //load up the rulebase

	        WorkingMemory workingMemory = ruleBase.newWorkingMemory();

	        //go !

	        for ( int i = 0; i < objects.length; i++ ) {
	        	workingMemory.assertObject( objects[i] );
	        }


	        workingMemory.assertObject( ruleResult );

	        workingMemory.fireAllRules();


		}catch( Exception e ) {
			e.printStackTrace();
			ExceptionUtil.throwAppException( "RuleExecuter.executeRule() :
Exception Occured :[" +e.getMessage()+"]");
		}

        return ruleResult;
	}





More information about the rules-users mailing list