|
|
|
|||
|
Threading IssuesHTTP servlets are typically capable of serving multiple clients concurrently. If the methods in your servlet that do work for clients access a shared resource, then you can handle the concurrency by creating a servlet that handles only one client request at a time. (You could also synchronize access to the resource, a topic that is covered in this tutorial's lesson on threads.) To have your servlet handle only one client at a time, have your servlet
implement the
Implementing the For example, the ReceiptServlet accepts a user's name and credit card
number, and thanks the user for their order. If this servlet actually
updated a database, for example one that kept track of inventory, then the
database connection might be a shared resource. The servlet could either
synchronize access to that resource, or it could implement the
public class ReceiptServlet extends HttpServlet
implements SingleThreadModel {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
...
}
...
}
| |||
|