Quoting from Geary's Advanced JavaServer Pages book, p. 14:
"Because servlet containers can reuse tag handlers, you must be diligent
about implementing the release method and careful about instantiating
resources in doStartTag [rather in the tags constructor]"
So the 'release' method is the key. You'll notice that the Struts tags use
the release method to clear their resources. Tag instances are not used
simultaneously, but released for re-use after they are done, so member
variables are ok, but care must be taken not to allow them to carry over to
future uses.
I highly recommend Geary's book for all Struts power users and developers,
especially in regards to custom tag development.
Erik
----- Original Message -----
From: "Bill Clinton" <[EMAIL PROTECTED]>
To: "struts" <[EMAIL PROTECTED]>
Sent: Wednesday, September 05, 2001 3:42 PM
Subject: Concurrency and Custom JSP tags
> Hello,
> I have been writing my own custom jsp tags, and have recently
> noticed that member properties of tags seem to be retained after the tag
> is complete.
>
> For example, lets say you have a tag that has an optional attribute
> called "message", and the tag is designed to print this attribute if it
> is passed. If you call this tag and pass "hello" as the attribute
> message on one page, then call this tag on another page without passing
> the attribute, it will still be set to "hello".
>
> This functions much like a servlet, which is multi-threaded but
> retains the values for member variables across different requests. I
> think most servlet programmers realize this and stay away from using
> non-static member variables. But it seems to me that custom JSP tag
> design encourages the use of attributes, which seems to be potentially
> very dangerous in an environment with a high volume of requests.
>
> I would like to know if anyone knows of any good links where
> concurrency issues in custom jsp tags are discussed more in depth.
> Also, I am curious to know if anyone has encountered any problems like
> this with the Struts tags. For example, if I set an "onmouseover" for a
> <html:checkbox> tag, do I have to worry about this attribute showing up
> in a <html:checkbox> tag called from a different page if both pages are
> loaded by different users at the same time?
>
> Thanks in advance for any info,
> Bill
>