Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP and thread safety within <% [..] %>

843833Aug 24 2001 — edited Aug 28 2001
Hi 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 !

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2001
Added on Aug 24 2001
10 comments
281 views