Currently I\'m reading \"Java concurrency in practice\", which contains this sentence:
Since the action of a thread accessing a stateless object can\'
An object without state, like instance variables that can change and vary depending on what has already happened to the object
A stateless object is an object that doesn't have any internal state (internal variable)
Stateless: it has no fields and references no fields from other classes.
The state for a particular computation exists solely in local variables that are stored on the thread’s stack and are accessible only to the executing thread.
One thread accessing a method/class cannot influence the result of another thread accessing the same method/class; because the two threads do not share state, it is as if they were accessing different instances.
Since the actions of a thread accessing a stateless object cannot
affect the correctness of operations in other threads, Stateless objects are threadsafe.
In simple terms state of object means value of internal variables in that object.
Stateful - state of object can be changed, means internal values off member variables of that object can be changed
How values can be changed?
By setting the value.
When can you set that value? When the variable is not final..
So, to make the class stateless, make the variable final, so that the value of that variable can't be changed neither in setter not in another method. It can be used only for computing.