The isThreadSafe Attribute
Format
<%@ page isThreadSafe="true" %> <% Default %>
<%@ page isThreadSafe="false" %>
Purpose
To tell the system when your code is not threadsafe, so
that the system can prevent concurrent access
Instructs servlet to implement SingleThreadModel
Notes
Default is true system assumes you have synchronized
updates to fields & other shared data
Supplying a value of false can degrade performance
43
JSP
www.corewebprogramming.com
Example of Non Threadsafe
Code (IDs Must Be Unique)
What s wrong with this code?
<%! private int idNum = 0; %>
<%
String userID = "userID" + idNum;
out.println("Your ID is " + userID + ".");
idNum = idNum + 1;
%>
44
JSP
www.corewebprogramming.com
22