You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kevin Klein <kk...@celerasystems.com> on 2003/06/04 23:10:38 UTC

JSP Variable Declarations not thread-safe?

I am using Tomcat 4.1.18 with JDK 1.4.0 on Solaris.

I have a page with a JSP variable declaration of the following form:

<%!
Client client;
%>

Followed by some inline code snippets:

<%
client = someForm.getClient();
%>

Followed by various sections of JSP tags where I reference attributes of
the object, e.g.:

<%= client.firstName %>

Problem is, when my application runs, the users are occasionally seeing
values from other user sessions.  This made me immediately suspect that
the generated JSP classes were not thread-sade.

I looked at the compiled code and saw that the declared variables are
translated to member variables of the HttpJspBase subclass.  If Tomcat
is not accurately tracking which JSP instances are in-use, there is a
potential for these member variables to be overwritten by other threads.

Is this a known bug or limitation in this version of Tomcat?  Am I doing
something wrong?

In the meantime, I've moved the variable declarations inside the code
snippet since that causes them to be declared in the method scope
instead of the class member scope.

Kevin Klein


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: JSP Variable Declarations not thread-safe?

Posted by Kevin Klein <kk...@celerasystems.com>.
Thanks.  'Twas never made clear in the specifications I saw.

> -----Original Message-----
> From: Tim Funk [mailto:funkman@joedog.org] 
> Sent: Wednesday, June 04, 2003 4:45 PM
> To: Tomcat Users List
> Subject: Re: JSP Variable Declarations not thread-safe?
> 
> 
> This is not a tomcat problem. Variables should not be 
> declared in a <%! %> 
> block. If you do - they should be read only and set at init 
> time of the Jsp 
> (via jspInit())
> 
> If you need to declare variables, then declare them via <% .. 
> %>. These will 
> be locally scoped to the _jspService method.
> 
> -Tim
> 
> Kevin Klein wrote:
> > I am using Tomcat 4.1.18 with JDK 1.4.0 on Solaris.
> > 
> > I have a page with a JSP variable declaration of the following form:
> > 
> > <%!
> > Client client;
> > %>
> > 
> > Followed by some inline code snippets:
> > 
> > <%
> > client = someForm.getClient();
> > %>
> > 
> > Followed by various sections of JSP tags where I reference 
> attributes of
> > the object, e.g.:
> > 
> > <%= client.firstName %>
> > 
> > Problem is, when my application runs, the users are 
> occasionally seeing
> > values from other user sessions.  This made me immediately 
> suspect that
> > the generated JSP classes were not thread-sade.
> > 
> > I looked at the compiled code and saw that the declared 
> variables are
> > translated to member variables of the HttpJspBase subclass. 
>  If Tomcat
> > is not accurately tracking which JSP instances are in-use, 
> there is a
> > potential for these member variables to be overwritten by 
> other threads.
> > 
> > Is this a known bug or limitation in this version of 
> Tomcat?  Am I doing
> > something wrong?
> > 
> > In the meantime, I've moved the variable declarations 
> inside the code
> > snippet since that causes them to be declared in the method scope
> > instead of the class member scope.
> > 
> > Kevin Klein
> > 
> >  
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: JSP Variable Declarations not thread-safe?

Posted by Tim Funk <fu...@joedog.org>.
This is not a tomcat problem. Variables should not be declared in a <%! %> 
block. If you do - they should be read only and set at init time of the Jsp 
(via jspInit())

If you need to declare variables, then declare them via <% .. %>. These will 
be locally scoped to the _jspService method.

-Tim

Kevin Klein wrote:
> I am using Tomcat 4.1.18 with JDK 1.4.0 on Solaris.
> 
> I have a page with a JSP variable declaration of the following form:
> 
> <%!
> Client client;
> %>
> 
> Followed by some inline code snippets:
> 
> <%
> client = someForm.getClient();
> %>
> 
> Followed by various sections of JSP tags where I reference attributes of
> the object, e.g.:
> 
> <%= client.firstName %>
> 
> Problem is, when my application runs, the users are occasionally seeing
> values from other user sessions.  This made me immediately suspect that
> the generated JSP classes were not thread-sade.
> 
> I looked at the compiled code and saw that the declared variables are
> translated to member variables of the HttpJspBase subclass.  If Tomcat
> is not accurately tracking which JSP instances are in-use, there is a
> potential for these member variables to be overwritten by other threads.
> 
> Is this a known bug or limitation in this version of Tomcat?  Am I doing
> something wrong?
> 
> In the meantime, I've moved the variable declarations inside the code
> snippet since that causes them to be declared in the method scope
> instead of the class member scope.
> 
> Kevin Klein
> 
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org