Thread Safety is a multi-threaded access, with a locking mechanism, when a thread accesses one of the class's data, protection, other threads can not access until the thread is finished reading, other threads are available. There is no data inconsistency or data contamination.
thread Insecurity is not providing data access protection, it is possible to have multiple threads change data successively causing the resulting data to be dirty data
Causes of thread safety problems
1, the thread task processing to the shared data, 2, the thread task has multiple operations on the shared data, one thread is working on the shared data, the other thread is involved in the operation, resulting in data errors.
The solution:
As long as the code that guarantees multiple operations to share data goes to a time period, executed by a thread, other threads are not allowed to participate in the operation during execution.
How to ensure safe use of synchronized keyword synchronized (object) {code to be synchronized}
How to analyze whether a thread has security implications one, whether there is shared data in the thread task, and whether there are multiple lines of code to manipulate the shared data.
What is thread-safe and thread-insecure