velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 8838] New: - context utility method calls are not thread safe
Date Mon, 06 May 2002 20:03:11 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8838>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8838

context utility method calls are not thread safe

           Summary: context utility method calls are not thread safe
           Product: Velocity
           Version: 1.3-rc1
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Build
        AssignedTo: velocity-dev@jakarta.apache.org
        ReportedBy: ivan.bella@capita.com


I am running a system that produces dynamic HTML output for many concurrent
users.  I have set up a set of velocity templates to takes a data model that
has been computed for a user, and produces the HTML output.  I have one
process that has initialized Velocity with parser.pool.size=20 and 20 threads
that concurrently execute the following:

   Velocity.mergeTemplate(myfile.vtl, "ISO8859-1", context, writer)

where context and writer are created anew for every execution of this line.
I absolutely guarentee that the data placed in the context is completely
seperate and different for each execution/thread.  Hence one thread accessing
data in the context cannot affect another thread accessing data in a different 
context.  Despite this, I am getting what appears to be random output.  When I
execute this system with only one thread, I always get the correct results.  
When I run with multiple threads, I periodically get altered results.
    I have reduced the templates down to one which seems to be the main culprit.

#foreach ($key in $DO.history())
  $key
  $Parts.part1($key) $Parts.part2($key) $Parts.part3($key)
#end

In this case, $DO.history returns a vector of strings.  $Parts is a utility
package in which part1, 2, and 3 return portions of the specified string.
They are static functions which simply use the indexOf and substring methods
on String.  They do not reference ANY global attributes.  In fact I placed 
System.out.println in the part methods and was able to show that the part
method was indeed returning the correct part.  However the resulting Velocity
output seemed to be outputting the wrong data!  It appears to be confusing the
output of $Parts.partx from one thread for the output in another!  I attempted
to look at the velocity code but was not able to quickly determine where I
should be looking.  Does anybody have a clue on this one?
                             Regards,
                                  Ivan Bella
                                  (ivan.bella@capita.com)

--
To unsubscribe, e-mail:   <mailto:velocity-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-dev-help@jakarta.apache.org>


Mime
View raw message