Skip to main content
6 of 15
edited title
user1787812
  • 769
  • 7
  • 16

State ownership - Thread safety

As mentioned by Java_author,

When defining which variables form an object's state, we want to consider only the data that object owns....

In many case, ownership and encapsulation go together—the object encapsulates the state it owns and owns the state it encapsulates....

A class usually does not own the objects passed to its methods or constructors, unless the method is designed to explicitly transfer ownership of objects passed in (such as the synchronized collection wrapper factory methods)...


For ensuring thread safety, a class need to draw a line on the state variables that it owns to ensure thread safety. Those state variables can be populated through generalization, association and Dependency Injection, what not.

Java author already gave(above) a parameter to assess state ownership for thread safety, the object encapsulates the state it owns and owns the state it encapsulates

For a non-thread-safe class to make thread-safe, Do you agree with this parameter to ensure thread safety?

user1787812
  • 769
  • 7
  • 16