Servlet Basic Concepts

Source: Internet
Author: User

One, the servlet is a Java class for other Java program calls, such as the Tomcat server, it can not run alone, it is run by the servlet engine to control and dispatch.


Second, servlet is a single case, multithreading

In the case of multiple clients accessing a servlet, the servlet is instantiated only once, that is, its init () method runs only once.

For each request, the servlet engine creates a new ServletRequest and servletresponse corresponding object, which is then passed as a parameter to the service () method, and the service calls Doget () or Dopost () on request.

Servlets are multi-threaded.


Three, multi-threaded security issues

For global variables, if high concurrency is the same variable, one thread request is not finished, and the next thread request comes.

This creates an error in the operation of the variable.

For example, for global variables I

When the first thread is taken out, the i++ operation is performed, the i++ is not executed, the next thread arrives, and the i++ operation is performed, in fact i++ executed two times, but the final result is only 1.


To solve this problem, or use a synchronous approach, use the synchronized



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Servlet Basic Concepts

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.