2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Why Struts Action classes not thread safe?

why are struts Action classes not thread safe? why it is like that.
userimage

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.

Struts 1 Actions are singletons and must be thread-safesince there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be
thread-safe or synchronized.

Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)

Answer is