Struts2 singleton and multiple instances

There are multiple instances of action in struts2 , that is, if a session generates an action 
, if it is a single instance, if two users modify the attribute value of an object, the attributes obtained by the two users will be different because of the different modification time of the users. , the results obtained by the operation are different.
For example: there is a piece of cloth with a length of 300cm, which can be made into a top (use 100cm) and a pair of pants (use 200cm); the lengths obtained by both A and B are both 300cm. ,
A wants to make a jacket and pants, he first cuts 100cm to make a jacket, waits for the jacket to finish before making pants, and B happens to take 100cm to make a jacket at this time, that's fine, when A finishes making a jacket and then makes pants It is found that the remaining cloth (100cm) is not enough to make pants... This affects the performance of the system. The solution is to give A and B a piece of 300cm cloth, so that the cloth will not be stolen by others. , is also the difference between single instance and multiple instances.
If it is set to a single instance, then multiple threads will share an ActionContext and ValueStack, so there will be problems when accessing concurrently
. It is an object that generates an Action for each request. The reason is: the Action of struts 2 contains data, for example, the data you fill in the page will be included in the member variable of the Action. If the Action is a single instance, these data will affect each other in a multi-threaded environment, such as causing the data filled in by others to be seen by you. So the Action of Struts2 is multi-case mode.
The problem arises, you can make the action of struts2 into a singleton modeWhat? When I used spring to generate actions, I found that the generated actions were all singletons. Doesn't this make my program run out of bugs by default? If the information submitted by the previous user is not filled in by the next user, it will go to the information entered by the previous user.
Background:
1) Struts2 will generate an Action instance to process each request.
2) Spring's Ioc container-managed bean is single instance by default.
First of all, considering the issue of data security, our Action should be guaranteed to be There are many cases, so that there will be no data problems. However, if some actions, such as only admins, can be operated, or some actions are shared by the whole site to improve performance, in this case, the singleton mode can be used .
Fortunately, Spring's bean can set its scope for each, so the above problem is not a problem. If you use a singleton, set scope="prototype" in spring's action bean configuration. Well, the problem ends here.
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325340755&siteId=291194637