Transferred from: http://www.cnblogs.com/JemBai/archive/2010/11/10/1873954.html
Struts+spring action should be configured as scope= "prototype"
<bean id=scope="prototype" class="Quickstart.action.PersonAction" >
<constructor-arg ref="Personservice"/>
</bean>
But for those DAO implementation class referral Scope= "Singleton", because these classes have no state, with Singleton only need to maintain an instance, obviously performance is higher.
In the configuration file, the bean is the singleton mode by default, and the application server starts immediately after the bean is created and can be reused later.
This leads to a problem where the bean's global variable is assigned, and the value is brought past the next use. In other words, the bean is stateful.
In the Web State, requests are multithreaded, and global variables can be modified by different threads, especially when concurrency brings unexpected bugs.
In the development, the traffic is very small, there is no concurrency, multithreading problems, programmers will most likely ignore this problem.
So when configuring the action bean, you should use scope="prototype"to create a new action instance for each request. This
In line with Struts2 's requirements, STRUTS2 creates a new action instance for each request. When the request is finished, the bean is
Destroyed, as garbage recovered.
Of course, you can also set scope= "session", can also avoid the web action concurrency problem, only for the current user to create a bean, until
The session disappears. In this case, the bean is stateful for the current user. The advantage is that fewer instances of the bean are created, and there is a
Point-of-order performance improvements
Application Scenarios:
1. Prototype should be used in most cases
2. If the user is not many, and frequent operation (frequent use of action), hardware generally, you can consider the session, may also be able to improve a little bit of performance.
Spring scope= "prototype", scope= "session"