JavaEE学习之路-Sharing Information

Web components, like most objects, usually work with other objects to accomplish their tasks. Web components can do so by doing the following.

  • Using private helper objects (for example, JavaBeans components).
  • Sharing objects that are attributes of a public scope.
  • Using a database.
  • Invoking other web resources. The Java Servlet technology mechanisms that allow a web component to invoke other web resources are described in
    Invoking Other Web Resources.

17.3.1 Using Scope Objects

Collaborating web components share information by means of objects that are maintained as attributes of four scope objects. You access these attributes by using the
getAttribute and setAttribute methods of the class representing the scope.
Table 17-2 lists the scope objects.

Table 17-2 Scope Objects

Scope Object Class Accessible From

Web context


javax.servlet.ServletContext


Web components within a web context. See Accessing the Web Context.


Session


javax.servlet.http.HttpSession


Web components handling a request that belongs to the session. See Maintaining Client State.


Request


Subtype of javax.servlet.ServletRequest


Web components handling the request.


Page


javax.servlet.jsp.JspContext


The JSP page that creates the object.

17.3.2 Controlling Concurrent Access to Shared Resources

In a multithreaded server, shared resources can 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.
  • Multiple threads within a web component accessing instance variables. A web container will typically create a thread to handle each request. To ensure that a servlet instance handles only one request
    at a time, a servlet can implement the SingleThreadModel interface. If a servlet implements this interface, no two threads will execute concurrently in the servlet‘s service method. A web container can implement this guarantee by synchronizing
    access to a single instance of the servlet or by maintaining a pool of web component instances and dispatching each new request to a free instance. This interface does not prevent synchronization problems that result from web components‘ accessing shared resources,
    such as static class variables or external objects.

When resources can be accessed concurrently, they can be used in an inconsistent fashion. You prevent this by controlling the access using the synchronization techniques described in the Threads lesson at
http://docs.oracle.com/javase/tutorial/essential/concurrency/.

时间: 2024-10-12 14:27:26

JavaEE学习之路-Sharing Information的相关文章

JavaEE学习之路-Writing Service Methods

The service provided by a servlet is implemented in the service method of a GenericServlet, in the doMethod methods (where Method can take the value Get,Delete, Options, Post, Put, or Trace) of an HttpServlet object, or in any other protocol-specific

JavaEE学习之路-Servlet Lifecycle

The lifecycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps. If an instance of the servlet does not exist, the web container: Load

JavaEE学习之路-Creating and Initializing a Servlet

Use the @WebServlet annotation to define a servlet component in a web application. This annotation is specified on a class and contains metadata about the servlet being declared. The annotated servlet must specify at least one URL pattern. This is do

JavaEE学习之路

What Is a Servlet? A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they

Python学习之路-Day1-Python基础

Python学习之路第一天 学习内容: 1.Python简介 2.安装 3.第一个Python程序 4.变量 5.字符编码 6.用户输入 7.表达式if..else语句 8.表达式for语句 9.break和continue 10.while循环 11.字符串格式化 1.python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承. 最新的TIOB

LTE学习之路(7)——LTE系统消息

1 系统消息包含: 主信息块(Master Information Block,MIB) 多个系统信息块(System Information Blocks,SIBs) 2 MIB 承载于BCCH——>BCH——>PBCH上 包括有限个用以读取其他小区信息的最重要.最常用的传输参数(如:系统带宽.系统帧号.PHICH配置信息) 时域:紧邻同步信道,以10ms为周期重传4次 频域:位于系统带宽中央的72个子载波(1.08MHz) 3  SIBs 除MIB外的系统信息,包括SIB1~SIB12:

LTE学习之路(8)——信令流程

1 在LTE中,需要识别3个主要的同步需求 符号和帧定时的捕获,通过它来确定正确的符号起始位置(如设置DFT窗位置): 载波频率同步,需要它来减少或消除频率误差的影响(注:频率误差是由本地振荡器在发射端和接收端间的频率不匹配和UE移动导致的多普勒偏移造成的): 采样时钟的同步 2 两个物理信号 主同步信号(PSS,Primary Synchronization Signal) 和辅同步信号(SSS,Secondary Synchronization Signal) 注:对于这两个信号的检测,不仅

Python学习之路—2018/6/14

Python学习之路-2018/6/14 1.浏览器与服务器 浏览器向服务器发送请求的过程为请求过程,服务器向浏览器响应的过程为响应过程. 2.简单的web应用程序 import socket sock = socket.socket() sock.bind(("100.113.14.43", 8080)) sock.listen(5) with open("index.html", "r") as f: # 先将样式写入html文件中,然后再读

Azure云平台学习之路(三)——Cloud Services

1.什么是云服务? 能够部署高度可用的且可无限缩放的应用程序和API.简而言之,就是你写的CMD程序按照一定的框架进行少量修改就能运行在Azure云平台上. 2.Azure云服务有什么特点? (1)专注应用程序而不是硬件,PaaS的一种. (2)支持多种框架和语言. (3)集成了运行状况监视和负载平衡. (4)自动缩放优化成本和性能 3.建立云服务之前,我们需要建立一个云存储,来记录我们的程序的日志信息(当然,这不是必须的) (1)选择左边导航栏的"存储".主面板上显示的是所有已有的存