Threading security issues for Servlets

Source: Internet
Author: User

The servlet itself does not have an issue with the so-called thread security, depending on how we use the servlet.

With the Tomcat Web container example, the servlet is loaded with a single instance in the container, and since the container is definitely running in multi-threaded mode, if the servlet uses static variables or instance variables, then it is certainly thread insecure. In order to ensure thread safety in high concurrency, the first prerequisite is stateless, in the actual development process, you can consider the use of local variables or threadlocal mechanism. The core mechanism for the spring framework to address thread safety issues is threadlocal. Threadlocal How to use this online information a lot, the use is relatively simple, it does not unfold. The official Oracle API instructions are attached below.

Threadlocal's API

Http://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html


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.