I can read in many websites that Struts Action classes are not thread safe . I am not able to understand why this is so .
Also I read a book which says "Struts action classes are cached and reused for performance optimization at the cost of having to implement the action classes in a thread-safe manner"
how is caching action classes and being thread safe related? .
How is caching action classes and being thread safe related?
If you cache and re-use instances of a class, allowing multiple threads to access the same instance simultaneously, then the class is inherently not thread-safe*. If you were to place mutable instance or static fields on the class, the results under concurrency would be unexpected and problematic. On the other hand, if each thread has its own instance of the class, then the class is inherently thread-safe.
* If the instance or static field is immutable, then its fine for multiple threads to access it simultaneously.