This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I've read the following difference between Struts 1 and Struts 2:
Struts 1 Actions are singletons and must be thread-safe since 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.)
I know that a singleton class is a class that can have only one instance. But I still do not understand the true nature of the difference between these two versions of Struts when using singleton and non-singleton strategies. Could you please tell me more about this and give me an example?
I'm not sure what you are looking for here. Struts 1 and 2 have different approaches to actions. Since Struts 1 only creates one instance of a particular action, the programmer must always keep thread safety in mind. For example, if one uses an instance variable in an action, it can create a race condition as multiple threads each set the variable to their own particular value.
Since Struts 2 creates an action instance for each request, this is one less thing the developer has to worry about.