[jboss-jira] [JBoss JIRA] Created: (JBRULES-1991) MVELSalienceExpression not thread-safe

Ingomar Otter (JIRA) jira-events at lists.jboss.org
Wed Mar 4 13:05:22 EST 2009


MVELSalienceExpression not thread-safe
--------------------------------------

                 Key: JBRULES-1991
                 URL: https://jira.jboss.org/jira/browse/JBRULES-1991
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-core
    Affects Versions: 4.0.7
            Reporter: Ingomar Otter
            Assignee: Mark Proctor
             Fix For: 4.0.8, 5.0.0.CR1


Scenario: 
* We are using Drools in a MT app with a shared rulebase and one WM per thread.
* We are using MVEL expressions to dynamically calculate salience from matched facts.
When runniing mutlithreaded, we could observe that expression would sometimes (1 in 500 times in our case) pick up the wrong salience value.
Looking at the source of MVELSalienceExpression.getValue() reveals that the method sets the WM and then evaluates the MVEL expression.
I assume that the MVELSalienceExpression is part of the rulebase and thus shared accross WMs. If this is true this is not thread-safe and may lead to the observed behaviour.  

Adding a simple synchronized fixes the problem in our case:
{code}
public synchronized int getValue(final Tuple tuple, final WorkingMemory workingMemory) {
        this.factory.setContext(tuple, null, null, workingMemory, null);
        return ((Number) MVEL.executeExpression(this.expr, this.factory)).intValue();
    }
{code}
However this may reduce overall concurrency in the application. A better solution might be to increase locality, ie having a "thread local" factory.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list