On Wed, 28 Aug 2002, Galbraith, Paul wrote:

> Date: Wed, 28 Aug 2002 13:34:07 -0400
> From: "Galbraith, Paul" <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: JSP thread safety
>
> Can someone clear up basics of JSP thread safety for me?

Same as for servlets -- instance variables are shared across all requests
to the same page, because there is only one instance of the page's servlet
class, and local variables are safe per request.

>  Can I declare
> variables in scriptlets and maintain thread safety?  Also, what about
> custom tags.

The best way to avoid thread safety issues in JSP pages is not use
scriptlets at all :-).  That's also going to lead you to much better
application designs.

>  They declare class variables, which makes me
> nervous...does the container ensure thread safety for custom tags
> (assuming they release properly in the release() method)?

More precisely, tag classes declare *instance* variables, which are unique
per instance of the Tag class.  The JSP page compiler generates code to
allocate any given instance to only one request at a time, but it is
perfectly free to reuse that instance more than once in the same page (if
the same tag is used more than once).

All the gory details of Tag instance lifecycle are in Chapter 10 of the
JSP 1.2 spec:

  http://java.sun.com/products/jsp/download.html

Anyone writing custom tags should become familiar with this stuff.

>  Cheers,
>
> Paul
>

Craig



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to