Concurrency concurrency security Issues for Java (1)

Source: Internet
Author: User

Multithreaded programming also brings some security issues while improving program performance, producing unpredictable results. The reason for this is that the sequence of operations in each thread in multiple threads is unpredictable, and the resource operations shared by each thread are likely to interact with each other. For example, statistics on the number of accesses to a page, the value of an int type is accumulated, each thread accepts the user request will be added to the int type. There is a security problem here, because the process of accumulating data is not an atomic operation, he needs to read the existing value, then accumulate it, and finally reset the value. If the value is updated by another thread after a thread reads an existing value, the a thread will eventually set an incorrect value.

Security issues occur because:

Multiple threads access a shared resource and make non-atomic modifications to the shared resource .

How to avoid security issues:

1. Do not share resources between threads.

2. The shared resource is an immutable resource.

3. Use synchronization for shared resource access.

Concurrency concurrency security Issues for Java (1)

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.