Thread safety means that there are no race conditions that allow multiple threads to execute at the same time, and the execution of the resulting idempotent blocks.
Java code Secure resources in multithreaded environments:
1, the basic data type of local variables;
2. A local variable of a non-basic data type that is not a return value and is not passed to a method accessed by another thread;
3. Subject to thread control and no escaping resources;
4, the shared state itself is a synchronized resource.
Thread control escape means that the creation, use, and destruction of resources are in the same thread and are never out of control of the thread.
Unsafe resources:
1, the Java class object member variable;
2, the sharing state is not synchronized;
3. Generate thread control to escape the resources;
4. The reference to the object is not thread-safe, even if it is an immutable object.
Multiple Threads: Thread safety