Thread Security summary and thread Summary

Source: Internet
Author: User

Thread Security summary and thread Summary
Thread Security Summary 1. What is thread security? When the server receives multiple accesses at the same time, the server allocates a thread for each request. If multiple threads call the same method and the method has global variables, the method also performs write operations to change the value of the variable. In this case, thread security issues may occur. The request may be different from the expected result, or even report an error during the system runtime. For example, if a set is cyclic and its value is changed, a running exception may occur when a thread traverses and changes its value. 2. solution. There are two first Methods: thread lock. A thread lock means that when multiple threads access a method at the same time, it determines whether another thread has completed this method. If other threads are not completed, these threads can only exclude waiting. Only when one thread finishes running can another thread run. The second method. Threadlocal local thread. Add the instance object to threadlocal and obtain the thread security issues in threadlocal. 3. thread security issues in spring. Springmvc creates a controler by default as a Singleton, because springmvc is a method-based presentation layer framework. When a request submits a parameter, it directly adds the variable to the member variable of the method, so as long as the member variables are not defined, thread security issues will not occur. Of course, when an instance object (member variable) is defined and a write operation is performed, thread security problems may occur. By default, spring recognizes bean objects as Singleton instances when they are created, and thread security issues may occur. Note. 4. struts is generally used with spring to create struts action objects for thread security issues in strus. strusts uses member variables when receiving request parameters, all thread security issues occur when action 1 is created as a singleton. Generally, multiple examples are used in struts. Each request creates an action.

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.