[
https://issues.apache.org/jira/browse/VELOCITY-536?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12486062
]
Nathan Bubna commented on VELOCITY-536:
---------------------------------------
"The only potential problem is that the VM or JIT could re-order instructions
within the synchronized block and end up setting init=true before the
constructor has completed and/or the reference has been set. So, although
32-bit primitives will work with DCL, the fact that we are using a 32-bit
primitive to protect a reference complicates things."
But the synchronization should only allow one thread at a time into the block
in which setup() is called and init is set to true. Even though those
instructions may be re-ordered, they should both be completed before another
thread enters the block. So their order doesn't matter. The reference being
checked (the init boolean) will be set properly before a second thread comes to
the double check of the init reference.
Please not that i'm not at all attached to using DCL here. Christopher's
suggestions are the best in the long run anyway. Of course, someone needs to
be willing to do that work and test it. As things are, Lei has tested that
this solution solves his problem, and i think it should be safe from the usual
DCL pitfalls. Until someone comes up with the superior patch, i'm inclined to
take this one. :)
> Velocity Engine throws NullPointer Exception when two people click on the
> same page at the same time for the first time
> -----------------------------------------------------------------------------------------------------------------------
>
> Key: VELOCITY-536
> URL: https://issues.apache.org/jira/browse/VELOCITY-536
> Project: Velocity
> Issue Type: Bug
> Components: Engine
> Affects Versions: 1.5
> Reporter: Lei Gu
> Attachments: 536-patch.txt, ASTDirective.java, ASTSetDirective.java,
> VelocimacroProxy.java
>
>
> Multi-thread concurrency issue
> During our concurrency testing, we observed NullPointer exceptions being
> thrown when two people hit the same page at the same time for the first time.
> Upon further investigation, it turns out that we need to synchronize the init
> method on ASTDirective, ASTSetDirective, and render method on
> ASTSetDirective, and VelocimacroProxy.
> Basically, the problem is introduced as the following; when two threads
> attempts to parse and render the same template at the same time. Thread1
> finishes parsing first and proceeds to the render method call, while thread 2
> is still busy parsing and will overwrite the existing parse tree that is
> being used by thread 1 for rendering purpose. Thus under certainly condition
> a NullPointer exception will be thrown.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]