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)