struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: JSP thread safety
Date Wed, 28 Aug 2002 18:31:49 GMT


On Wed, 28 Aug 2002, Kevin A. Smith wrote:

> Date: Wed, 28 Aug 2002 14:24:03 -0400
> From: Kevin A. Smith <KevinA.Smith@sas.com>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> Subject: RE: JSP thread safety
>
> It sounds like tag instances can be recycled after each request

Close ... recycling in the same *page* is allowed, but that's primarily a
performance optimization issue.

> but not
> shared between two requests executing at the same time.

That is correct.  Basically, a tag author doesn't need to worry about
thread safety for its instance variables -- the container ensures that
only one thread at a time will use any given instance.

> In a way this
> makes sense. Otherwise, it would be very difficult for tags to maintain
> state during page processing (I'm thinking of parent/child tags here).
>

That's for sure :-).

> --Kevin

Craig

>
> -----Original Message-----
> From: Galbraith, Paul [mailto:Paul.Galbraith@T4G.com]
> Sent: Wednesday, August 28, 2002 2:21 PM
> To: Struts Users Mailing List
> Subject: RE: JSP thread safety
>
>
> Ok, I think I understand for scriptlets: essentially, any JSP declarative tag is not
thread-safe, but standard scriptlet desclarations are instance variables and thus threadsafe
(I'm inferring).
>
> so, <%! int i; %> is avaialable to all requests, but <% int i; %> is not.
>
> I don't understand for tags, however.  What is "action in the JSP" ([sic] from quote
below)?  I'm interested in how class variables in tag classes relate to HTTP requests...I
can't sort that out from the quote below, sorry!  They're instantiated for each request, I
take it, and then reused within that request if more than one reference is made?
>
> Paul
>
> -----Original Message-----
> From: James Higginbotham [mailto:jhigginbotham@betweenmarkets.com]
> Sent: August 28, 2002 2:03 PM
> To: Struts Users Mailing List
> Subject: RE: JSP thread safety
>
>
> Well, the JSP spec says it all - may want to take a look, or just write
> a JSP page and have the compiler keep the generated code so you can look
> at what it does.
>
> JSP 7.1.2.1:
> <quote>
> The JSP page implementation class instantiates a tag handler object, or
> reuses
> an existing tag handler object, for each action in the JSP page. The
> handler object
> is a Java object that implements the javax.servlet.jsp.tagext.Tag
> interface. The
> handler object is responsible for the interaction between the JSP page
> and
> additional server-side objects.
> </quote>
>
> Thus, the JSP compiler will generally create a new instance to process
> the tag in question. This is how nested tags may find their parents and
> be able to lookup values within there.
>
> As for declared variables:
>
> <quote>
> JSP.2.11.1 Declarations
> Declarations are used to declare variables and methods in the scripting
> language
> used in a JSP page. A declaration should be a complete declarative
> statement, or
> sequence thereof, according to the syntax of the scripting language
> specified.
> Declarations do not produce any output into the current out stream.
> Declarations are initialized when the JSP page is initialized and are
> made
> available to other declarations, scriptlets, and expressions.
>
> Examples
> For example, the first declaration below declares an integer, global to
> the
> Scripting Elements 57
> page. The second declaration does the same and initializes it to zero.
> This type
> of initialization should be done with care in the presence of multiple
> requests
> on the page. The third declaration declares a method global to the page.
> <%! int i; %>
> <%! int i = 0; %>
> <%! public String f(int i) { if (i<3) return("..."); ... } %>
> Syntax
> <%! declaration(s) %>
>
> </quote>
>
> As for anything else generated for a JSP tag (including custom tags),
> its declared within the body of the generated method by the JSP compiler
> and thus they go on the stack for the thread, rather than the heap.
>
> James
>
> > -----Original Message-----
> > From: Kevin A. Smith [mailto:KevinA.Smith@sas.com]
> > Sent: Wednesday, August 28, 2002 12:54 PM
> > To: Struts Users Mailing List
> > Subject: RE: JSP thread safety
> >
> >
> > Not sure about the taglib class variables (but I'd really
> > like the answer to that one also).
> >
> > With respect to JSP thread safety, my understanding was that
> > any variables declared in the page were only in scope during
> > the execution of the page, much like variables in method
> > scope. If the pages in question are also declaring private
> > member variables or static variables, well that's another
> > story entirely.
> >
> > --Kevin
> >
> > -----Original Message-----
> > From: Galbraith, Paul [mailto:Paul.Galbraith@T4G.com]
> > Sent: Wednesday, August 28, 2002 1:34 PM
> > To: struts-user@jakarta.apache.org
> > Subject: JSP thread safety
> >
> >
> > Can someone clear up basics of JSP thread safety for me?  Can
> > I declare variables in scriptlets and maintain thread safety?
> >  Also, what about custom tags.  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)?  Cheers,
> >
> > Paul
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:struts-user-> unsubscribe@jakarta.apache.org>
> > For
> > additional commands,
> > e-mail: <mailto:struts-user-help@jakarta.apache.org>
> >
> >
>
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
>
>


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


Mime
View raw message