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.
- Struts and JSP page technology
- Detailed explanation of JSP-to-Servlet Conversion
- Analysis of features of Servlet2.5
- About Servlet/JSP server redirection
- Application of Ajax Servlet instances in Network Programming