Hi
i have a question about a
thread safety. I dont understand the output of running this example. This is the example p.196 of manning scwcd study kit. I have slightly modified the example
<html><body>
<%@ page isThreadSafe="false" %>
<%! int j=0; %>
<%
for (int i=0; i<4; i++)
{
out.print("The value of j is " + j + "<br>");
j++;
Thread.currentThread().sleep(1000);
}
%>
</body></html>
Now when isthreadsafe is set to false this means it uses the singlethread model, therefore forcing the container to use a different instance for each thread. Now...i open this example with 2 browser windows, and run the first, then immediately i switch to the second and run it.
I see the first one start off saying value of j is 0, 1 , 2 ,3 (as expected). Thats fine, then i see the second (running concurrently) saying 4, 5, 6, 7 (not as expected). Now i would have thought the the second would be a new instance, thefore j would have a new value starting from zero ??? this is my problem
Could anyone explain this to me???
PS Now if i didnt run both concurrently i would expect to see the same results and the container doesnt need to necessarily use 2 different instances with the singlethreadmodel, just not with the same thread at the same time.