Brace yourselves, this could get complicated: The basic issue is this: I am concerned about the thread saftey of my Custom Tag. I have a tag that has one "property" called page. Hence, here is the basic outline of my custom tag:
Now, to call my tag in the JSP I use: <tags:mytag page="hello"> The problem comes when I use this little plug in other pages and the "page" attribute is being set to all kinds of things. Is this thread safe? I am wary of this, and not convinced at all that when I call it with "hello" that I won't get back something else from a different call occuring at the same time. Anyone offer any insight or fixes? Thanks, Jason SCJP
The way I read the JSP 1.2 specification, objects created to implement taglibs are re-used just like servlet objects. Therefore you should not use instance variables like this. Bill
As far as I am aware this IS thread safe. I am sure that a new Tag handler is created to handle EVERY request... instance variables should be fine. Tag handlers are reused (one a request has finished with it!), but you SHOULD clean up for instance varaibles in the release() method if you rely on them being initailised correctly.... S
<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
As far as I undertand once a TagHandler is invoked then no other thread can acccess it untill it is finished, so you are safe. However they are reused so instance variables you may have set should be nulled in the doEndTag method. The resaon for this is if you call the tag again and you do not set the instance variables then they can have the values of some previous time that the tag was run and you could get some erroneous results. Trevor
Adam Chace<BR>Author of :<A HREF="http://www.amazon.com/exec/obidos/ASIN/193011009X/electricporkchop/102-2552103-3190518" TARGET=_blank rel="nofollow">JSP Tag Libraries</A><BR><A HREF="http://www.chalkcreek.com" TARGET=_blank rel="nofollow">Chalk Creek Software</A>
Jason Stortz
Ranch Hand
Joined: Jan 11, 2001
Posts: 68
posted
0
Thanks for all your replies everyone. I really appreciate them. And it is a big relief to find out what I have. That makes things pretty easy and nice to deal with. Thanks again. Jason