servlet Thread Safety

Source: Internet
Author: User

  • When multiple clients access the same servlet concurrently, the Web server creates a thread for each request and invokes the Servlet's service method on that thread, so if the same resource is manipulated within the service method, There may be a thread safety issue
  • If a servlet implements the Singlethreadmodel interface, the Servlect engine invokes its service method in single-threaded mode
  • There is no task method defined within the Singlethreadmodel interface , as long as the declaration of implementing the Singlethreadmodel interface is added to the definition of the servlet class
  • The Servlet,servlet engine, which implements the Singlethreadmodel interface , still supports multithreaded concurrent access to the servlet by producing multiple servlet instance objects . Each concurrent thread invokes a separate Servlet instance object, respectively
  • implementing the Singlethreadmodel interface does not really address the thread safety of the servlet, because the servlet engine creates multiple servlet instance objects. The real solution to multithreading security is that a Servlet instance object is called concurrently by multiple threads. In servlet API 2.4, Singlethreadmodel has been marked as deprecated (obsolete)

therefore, to solve the thread safety problem, it is best to use synchronized

servlet Thread Safety

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.