background image

Controlling Concurrent Access to Shared Resources

<< Handling Servlet Errors | Accessing Databases >>
<< Handling Servlet Errors | Accessing Databases >>

Controlling Concurrent Access to Shared Resources

TABLE 4­3
Scope Objects
Scope Object
Class
Accessible From
Web context
javax.servlet.ServletContext
Web components within a web context. See
"Accessing the
Web Context" on page 124
.
Session
javax.servlet.http.HttpSession
Web components handling a request that belongs to the
session. See
"Maintaining Client State" on page 125
.
Request
subtype of
javax.servlet.
ServletRequest
Web components handling the request.
Page
javax.servlet.jsp.JspContext
The JSP page that creates the object. See
"Using Implicit
Objects" on page 145
.
Figure 4­1
shows the scoped attributes maintained by the Duke's Bookstore application.
Controlling Concurrent Access to Shared Resources
In a multithreaded server, it is possible for shared resources to be accessed concurrently. In
addition to scope object attributes, shared resources include in-memory data (such as instance
or class variables) and external objects such as files, database connections, and network
connections.
Concurrent access can arise in several situations:
Multiple web components accessing objects stored in the web context.
Multiple web components accessing objects stored in a session.
currency
Session
Attribute
cart
Session
Attribute
BookStoreServlet
BookDetailsServlet
CatalogServlet
ShowCartServlet
CashierServlet
ReceiptServlet
hitCounterFilter
OrderFilter
hitCounter
bookDB
orderCounter
Web
Context
Attribute
FIGURE 4­1
Duke's Bookstore Scoped Attributes
Sharing Information
The Java EE 5 Tutorial · September 2007
106