1. What is a single case of multiple cases:
The so-called Singleton is that all requests are handled with an object, such as our common service and DAO layer objects are usually singleton, and many cases refer to each request with a new object to handle, such as action;
2. How to produce a single case of multiple cases:
In common SSH, Singleton is the default in spring, and if multiple cases are to be generated, add scope= "prototype" to the bean in the config file;
3. Why use single-case multiple examples:
The reason for using a singleton is that there is no need to create a new object for each request, which wastes both CPU and memory;
Multiple cases are used to prevent concurrency problems, that is, one request changes the state of an object, and the object processes another request, while the previous request changes the state of the object causing the object to handle the other request incorrectly;
There is only one criterion for single and multiple cases:
When the object contains a state that can be changed (more precisely in the actual application, the state will change), then more than one case;
4. When to use a single case? When to use multiple cases?
For STRUTS2, the action must be in multiple cases, because the action itself contains the value of the request parameter, which can be changed in the state;
For STRUTS1, the action can be a singleton, because the value of the request parameter is placed in the actionform, not in the action;
In addition, it is not said that the service or DAO must be a singleton, the standard with the 3rd, we have seen some service also contains a change of state, while the execution method also relies on the state, but the same use of the Singleton, so there will be hidden bugs, Concurrency bugs are often difficult to reproduce and find;
Java single and multi-instance explanations