Describes how to run a Servlet instance.

Source: Internet
Author: User

I. Servlet Running Mechanism in Web containers

1. Run a single stateless Servlet instance

That is, the running mode of a Servlet instance is called by multiple threads in the Web container.

2. run multiple Servlet instances

There are multiple Servlet Instance Object pools in the Web Container and multiple Web Container threads to call and execute them separately.

Ii. Servlet connection to the database

1. One-to-one

Each Servlet instance has a direct database connection.

Specific methods include:

1> in each processing method of the Servlet instance, the database connection is called every time, and then the connection is used for database query and other operations. Finally, the connection is closed and released.

2> when the Servlet instance is initialized, it connects to a "long" database connection until the Servlet instance closes and releases the database connection during destroy.

Because the current database operations are mainly queries, and there are no operations such as adding or modifying databases, multi-User Service Query, multi-threaded Web containers, and operations on the same database connection of a Servlet should not cause data operation synchronization and other problems.

2. Use the Web Container Data Source

Here we mainly use the data source of the Web Container-database connection pool.

Theoretically, this method can provide the best performance. This is also a test of the performance of various Web Container products in the database connection pool.

Here we mainly look at the optimal configuration of Web containers in various application scenarios.

How to connect a Servlet to a data source:

Servlet directly retrieves the data source and its connection object from the Web container configuration, and then operates the database through this connection object. The Web Container manages database connection objects.

  1. Struts and JSP page technology
  2. Detailed explanation of JSP-to-Servlet Conversion
  3. Analysis of features of Servlet2.5
  4. About Servlet/JSP server redirection
  5. Application of Ajax Servlet instances in Network Programming

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.