[stringtemplate-interest] Thread safety of templates - am I correct in thinking getInstanceOf?
Steven Atkinson
satkinson at netflix.com
Tue Oct 23 17:09:17 PDT 2007
Hi folks,
I am a long-time ANTLR user but I am new to StringTemplate, and need to
use it in anger soon now.
I have about 500 StringTemplate objects that I am loading in to memory
on demand (caching).
In my application at any time I will have multiple threads needing to
supply their own attributes and use each of these 500 templates.
I do this so that I am not re-chunking the templates each time they are
used.
To handle multiple threads needing to supply differing attributes to the
same StringTemplate at the same time, it looks like I should be using
StringTemplate.getInstanceOf to re-use the chunks but have different
attributes.
i.e.
String clientThreadMethod() {
StringTemplate template = // find one of the cached 500 templates;
StringTemplate instanceST = template.getInstanceOf();
instanceST.setAttribute("name", "foo");
...
return instanceST.toString();
}
This would seem to work just fine until we have nested templates to
consider - a quick reading through the code makes me think that
instanceSTs are created to handle nested template references, but I just
wanted to check in with the group to see whether this is true, and also
just check that sharing the chunks and keeping the attributes per-thread
was the way to go for using StringTemplate in a high-volume
multi-threaded shared-StringTemplate environment.
Thanks in advance,
Steve Atkinson.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071023/6d871041/attachment.html
More information about the stringtemplate-interest
mailing list