Servlet thread security issues

Source: Internet
Author: User

Recently I was thinking about the thread security issue of JSP and servlet.

According to my understanding, the instance variables in the servlet are non-thread-safe (the variables are on the stack), while the service, dopost, the variables declared in the doget method are thread-safe (the variables are on the stack ). Only one servlet instance is maintained in the Web server, and a new thread is added for processing each client connection. So is thread security a question about thread security of class variables in multi-thread classes?

We know that every new thread generates a new instance variable in the multi-threaded class, so servlet is unlikely to be an instance variable in the Thread class. Of course, it is not like a parameter variable or a temporary variable. Is the servlet class a static variable in this multi-threaded class?

In addition, the action class in the Struts framework is not thread-safe. As far as I know, the actionservlet class will perform some delegate actions in the action. Can this be understood: In the setlvet-based Web server, all servlet or servlet delegate-based class variables are not thread-safe, the only safe thing is that the class method is not a temporary variable of the class. If there is a class variable in the Temporary Variable, this rule is recursive.

Related Article

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.