Java EE Learning path-sharing information

Source: Internet
Author: User


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

    • Using Private Helper Objects (for example, JavaBeans components).

    • Sharing objects that is attributes of a public scope.

    • Using a database.

    • Invoking other Web resources. The Java Servlet technology mechanisms-a Web component to invoke other Web resources is described ininvoking O Ther Web Resources.

17.3.1Using Scope Objects

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

Table 17-2 Scope Objects

from
Scope Object Class Accessible

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 this belongs to the session. See maintaining Client State.

Request

Subtype ofjavax.servlet.ServletRequest

WEB components handling the request.

Page

javax.servlet.jsp.JspContext

The JSP page that creates the object.


17.3.2Controlling Concurrent Access to Shared Resources

In a multithreaded server, the 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 accessing objects stored in the web context.

    • Multiple Web accessing objects stored in a session.

    • Multiple threads within a Web component accessing instance variables. A web container would typically create a thread to handle each request. To ensure. A servlet instance handles only one request at a time, a servlet can implement the singlethreadmodel< /code> interface. If a servlet implements this interface, no threads would execute concurrently in the Servlet's service method. A web container can implement this guarantee by synchronizing access to a single instance of the Servlets 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 the result from Web Components ' accessing shared resources, such As static class variables or external objects.

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

Java EE Learning path-sharing information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.