Hi Chris, The issue is not with parsing the template because directives and set directives are not parsed when parsing the calling template, rather they are parsed mostly during template.merge call. We can easily get into a racing condition when two threads are trying to render both template at the same time and they race to parse the underline directive and set directive, which will result in NullPointer exception being thrown depending on the size of the template, etc. Thanks. -- Lei
Christopher Schultz-2 wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Lei, > > Lei Gu wrote: >> 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. > > It sounds to me like we should synchronize at a higher level to avoid > double-parsing, instead of synchronizing the low-level methods in order > to avoid any ill-effects of double-parsing. I must admit that I don't > know anything specific about the classes mentioned above, but they sound > like they are part of the AST itself. I would imagine that serializing > access inside getTemplate (based upon the template stored within > Velocity's template cache, not the cache itself) would be cleaner and > would result in less wasted effort during runtime. > > Forgive me if I've got this all wrong ;) > > - -chris > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.7 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFGDl1G9CaO5/Lv0PARAjjeAJ9AhEdyUbyJ+vN5zaa6lWLOvItzTACePd04 > oHl+PVMOBOi/7fkW5mZLekw= > =wEn7 > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/Fix-for-isse-number-223-and-fixes-for-multi-thread-concurrency-issue-in-Velocity-Engine-tf3494132.html#a9767906 Sent from the Velocity - Dev mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
