Reputation: 90
Is it safe to say that an object is thread-safe in Java if its class contains no instance variables that can be changed and no static variables?
Upvotes: 3
Views: 69
Reputation: 53819
Totally safe, as long as it does not extend a non thread-safe class.
If an object is stateless, it can safely be shared by several threads.
That is also why it is encouraged to use immutable objects in multi-threaded environment as their state cannot be concurrently modified.
Upvotes: 4