We know that the root cause of thread safety is:
Multiple threads access a shared resource and make non-atomic modifications to the shared resource.
It is very complex and error-prone to find out which threads have access to the same resource in a large program. So when developing a thread-safe program, you encapsulate the shared resource and control the thread's access to it.
In Java, object-oriented provides a way to encapsulate and access internal resources, through the face object, not only can write out the structure elegant, high maintainability class, but also help to write thread security class.
encapsulates and controls access to shared resources in Java through object-oriented technology .
Using object-oriented not only makes it easy to encapsulate and control shared resources, but it is also easy to build multiple packages of shared resources. A thread-safe class that builds multiple shared resources through multiple thread-safe classes is much easier to consider in one program than to control multiple shared resources.
Thread- safe programs that make it easier to write complex multi-shared resources through the thread-safety class combination .
Java Concurrency Build Thread Safety Program (2)