NonStop Servlets for JSP System Administrator's Guide
Programming and Management Features
NonStop Servlets for JavaServer Pages (NSJSP) System Administrator’s Guide—525644-001
4-6
Context-Management
Context-Management
Because the same servlet or JSP can be running in multiple processes in the same
web container, a series of requests to the servlet class may not be serviced by the
same process. This situation has important implications for the design of a servlet:
•
No data maintained by a servlet can be presumed to apply to the servlet class
collectively. Class data applies only within a process.
•
Context created in memory by one request may not be available to subsequent
requests because subsequent requests might not execute in the same data space.
Therefore, a servlet that wishes to make context available should write the context
to disk before returning.
Unless you are using session tracking, a feature of the Servlet API, the only way to
ensure that the same process will service a series of requests is to limit the web
container to one process (Maxservers=1). A server class limited in this way retains
the quality of persistence but loses the scalability advantage of a server class. To
support sessions, the web container’s Numstatic and Maxservers attributes must
have the same value unless you are using persistent sessions and turn off session-
based load balancing. For information on turning off session-based load balancing,
refer to -DSessionBasedLoadBalancing=[ true | false ] on page 3-5.
Multithreading – Spawning Java Threads
The NSJSP product supports spawning Java threads from within a servlet or JSP.
When multiple users access a servlet simultaneously, the web container does not
instantiate a new servlet instance for each user. When a client access the servlet, the
service() method is invoked in a separate thread. Therefore each client is sharing
the data of the servlet. In most cases this is by far the most efficient method of
handling multiple requests for servlets that do not contain client data.
You should be aware that multithreading may require you to allow for threading
synchronization. Every client has access to each field in the servlet; the fields of the
servlet are being shared by each client. If a field contains client-specific data, then the
access to that field must be synchronized.
Example 4-1. Use of getAttribute() Method to Obtain Environment Variables
out.println("</pre>");
Enumeration x =
(Enumeration)req.getAttribute("com.tandem.servlet.attribute_names");
out.println("<pre>");
while (x.hasMoreElements()) {
String pn = (String)x.nextElement();
out.println(pn +" = " + req.getAttribute(pn) );
}
out.println("</pre>");