You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Edward L. Knoll" <ed...@cosd.fedex.com> on 2004/12/23 20:49:29 UTC
Concurrency problems with variable management?
We seem to have isolated a couple of concurrency problems to the
handling of (template scope) variables in two different contexts. I
will include code fragments to illustrate the problems. Corporate
proprietary policies will not allow me to send the entire source or the
data. Within the next couple of weeks it is my intent to attempt to
reproduce both of these problems with simple/benign examples which (if
successful) I will submit with a bug report.
Our thread test driver is running 20 threads on a 8 processor box. Each
thread is performing the same set of 16 different transformations (in a
couple of different orders). Each transformation is performed by a SAX
processing chain. The XSL transforms are loaded into templates. The
classes used in the SAX processing chain are recreated for each
transformation.
In the first example, a local variable is passed to two separate
templates. The value of the IntermediateValue variable changes between
the two xsl:call-template invocations. The incorrect value can be found
in the input XML. We believe the incorrect value is being picked up
from another thread. This error will generally occur once or twice
every 10 runs (of the 20 threads).
<xsl:template match="sep-gmt-post-timestamp" priority="20.0">
<xsl:variable name="IntermediateValue"
select="concat(normalize-space(.),
substring-after(../event-creation-timestamp,'Z'))" />
<xsl:call-template name='TransformField'>
<xsl:with-param name="IntermediateValue"
select="$IntermediateValue" />
<xsl:with-param name="OtherElements">
<xsl:call-template name="FormatDateTime">
<xsl:with-param name="Input">
<xsl:value-of select="$IntermediateValue" />
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
The other error occurred on almost every test run. A local variable
inside of a recursive template call appeared to be changing. The
"count" was sometimes '1' when it should have been '0'. We totally
eliminated the local variables and the problem when away. I've included
old and new code fragments:
<!--Original/Broken Code-->
<xsl:template name="OutputFieldAndValue">
<xsl:param name="count" />
....
<xsl:variable name="paddingSpaces">
<xsl:value-of select="$num * 4" />
</xsl:variable>
....
<xsl:variable name="calculatedPadding">
<xsl:value-of
select="substring($TranslatedSpaces,1,$paddingSpaces)" />
</xsl:variable>
....
<xsl:for-each select="*">
<xsl:call-template name="OutputFieldAndValue">
<xsl:with-param name="count" select="$count+1" />
</xsl:call-template>
</xsl:for-each>
....
</xsl:template>
<!--New/Working Code-->
<xsl:template name="OutputFieldAndValue">
<xsl:param name="count" select="0" />
<xsl:param name="indent" select="''" />
....
<xsl:for-each select="*">
<xsl:call-template name="OutputFieldAndValue">
<xsl:with-param name="count" select="$count+1" />
<xsl:with-param name="indent"
select="substring($TranslatedSpaces,1,$count*4)" />
</xsl:call-template>
</xsl:for-each>
....
</xsl:template>
--
Edward L. Knoll Phone (FedEx) : (719)484-2717
e-mail (FedEx) : edward.knoll@fedex.com
e-mail (personal) : edward@elknoll.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
Re: Concurrency problems with variable management?
Posted by Christine Li <jy...@ca.ibm.com>.
Hi, Edward
Thanks for trying to identify the problem. Once you can reproduce the
problem, please one a bug report and attach a test case to demonstrate the
problem http://nagoya.apache.org/jira/
Thanks,
Christine Li
XSLT Development
IBM Toronto Lab
Tel: (905)413-2601
Email: jycli@ca.ibm.com
"Edward L. Knoll" <ed...@cosd.fedex.com>
12/23/2004 02:49 PM
Please respond to
xalan-dev
To
xalan-dev@xml.apache.org
cc
Subject
Concurrency problems with variable management?
We seem to have isolated a couple of concurrency problems to the
handling of (template scope) variables in two different contexts. I
will include code fragments to illustrate the problems. Corporate
proprietary policies will not allow me to send the entire source or the
data. Within the next couple of weeks it is my intent to attempt to
reproduce both of these problems with simple/benign examples which (if
successful) I will submit with a bug report.
Our thread test driver is running 20 threads on a 8 processor box. Each
thread is performing the same set of 16 different transformations (in a
couple of different orders). Each transformation is performed by a SAX
processing chain. The XSL transforms are loaded into templates. The
classes used in the SAX processing chain are recreated for each
transformation.
In the first example, a local variable is passed to two separate
templates. The value of the IntermediateValue variable changes between
the two xsl:call-template invocations. The incorrect value can be found
in the input XML. We believe the incorrect value is being picked up
from another thread. This error will generally occur once or twice
every 10 runs (of the 20 threads).
<xsl:template match="sep-gmt-post-timestamp" priority="20.0">
<xsl:variable name="IntermediateValue"
select="concat(normalize-space(.),
substring-after(../event-creation-timestamp,'Z'))" />
<xsl:call-template name='TransformField'>
<xsl:with-param name="IntermediateValue"
select="$IntermediateValue" />
<xsl:with-param name="OtherElements">
<xsl:call-template name="FormatDateTime">
<xsl:with-param name="Input">
<xsl:value-of select="$IntermediateValue" />
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
The other error occurred on almost every test run. A local variable
inside of a recursive template call appeared to be changing. The
"count" was sometimes '1' when it should have been '0'. We totally
eliminated the local variables and the problem when away. I've included
old and new code fragments:
<!--Original/Broken Code-->
<xsl:template name="OutputFieldAndValue">
<xsl:param name="count" />
....
<xsl:variable name="paddingSpaces">
<xsl:value-of select="$num * 4" />
</xsl:variable>
....
<xsl:variable name="calculatedPadding">
<xsl:value-of
select="substring($TranslatedSpaces,1,$paddingSpaces)" />
</xsl:variable>
....
<xsl:for-each select="*">
<xsl:call-template name="OutputFieldAndValue">
<xsl:with-param name="count" select="$count+1" />
</xsl:call-template>
</xsl:for-each>
....
</xsl:template>
<!--New/Working Code-->
<xsl:template name="OutputFieldAndValue">
<xsl:param name="count" select="0" />
<xsl:param name="indent" select="''" />
....
<xsl:for-each select="*">
<xsl:call-template name="OutputFieldAndValue">
<xsl:with-param name="count" select="$count+1" />
<xsl:with-param name="indent"
select="substring($TranslatedSpaces,1,$count*4)" />
</xsl:call-template>
</xsl:for-each>
....
</xsl:template>
--
Edward L. Knoll Phone (FedEx) : (719)484-2717
e-mail (FedEx) : edward.knoll@fedex.com
e-mail (personal) : edward@elknoll.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org