Can an object be called thread safe or not?
Can an object be said to be thread-safe in Java if its class contains no instance variables that can be changed and no static variables?
+3
Prasad
source
to share
1 answer
Completely safe as long as it doesn't extend a thread-independent class.
If an object is stateless, it can be shared safely by multiple threads.
This is why it is recommended to use immutable objects in a multithreaded environment, since their state cannot be changed at the same time.
+4
Jean Logeart
source
to share