JSP and thread safety within <% [..] %>
843833Aug 24 2001 — edited Aug 28 2001Hi folks !
Consider the following code within a MULTITHREADED JSP, meaning "isThreadSafe" equals "true":
[....]
<% String temp = someObjectInSessionContext.getString() %>
<TABLE>
<TR>
<TD><%= temp%></TD>
</TR>
</TABLE>
----------------------------------------------------
If I learned my lessons well enough, then this code should NOT be threadsafe.
Consider two threads:
- the first thread sets temp
- it goes on until it reaches the <TR> tag
- then it looses the CPU
- the second thread sets temp and then looses the CPU
- the first thread gets the CPU, but now when it reaches the <%= temp %> tag, temp holds the value of the second thread.
Is this right ?
What would be the best way to make it thread safe, besided setting the page directive "isThreadSafe"to "false" ?
Thank you very much !