What's the difference between Struts1 and Struts2?

Source: Internet
Author: User

In general, the Struts1 action is a singleton mode, so the developer must ensure that it is thread-safe or synchronous, because there is only one instance of each action in struts 1 that handles all requests.

However, when developing with struts 1, we did not take into account the thread-safety issue, because we used the basic local variables in action, and "Local variables are thread-safe." Because each execution of a method creates a local variable in a separate space, it is not a shared resource. The local variable includes the parameter variable of the method "(forget where it was quoted). In struts 1, all variables are defined in the action in the method we are going to execute (the Execute method in action or the method specified in Dispatchaction), which we use to encapsulate the actionform of the client request parameters, is also passed as a parameter, and it is also a local variable, so there is no thread safety issue.

The action object of Struts 2 produces an instance for each request, so there is no thread-safety issue, although many global variables are defined in the action.

The Struts 2 framework creates a separate thread to handle every user request, and the value stack valuestack is accompanied by a local thread. In the process of the existence of this thread, the value stack can be accessed at will, which guarantees the security of the value stack.

In Struts 2, Actioncontext is a local thread, which means that the actioncontext content in each thread is unique. So developers don't have to worry about the thread safety of the action.

What's the difference between Struts1 and Struts2?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.