Single Case multiple cases

Source: Internet
Author: User

Singleton multiple examples need to understand two questions:
1.  What is a single case, and
2.  How to produce a single case of multiple cases;
3.  Why use a single case of multiple cases
4.  When to use a single case, when to use multiple cases;
1.  What is a singleton:
The so-called Singleton is that all requests are handled with an object, such as our common service and DAO layer objects are usually single-case, In other cases, each request is treated with a new object, such as action; 
2.  How to produce singleton multiple cases:
     in common ssh, the singleton is the default in spring, If you want to produce multiple cases, add scope= "prototype" to the Bean in the configuration file,  
3.  Why use singleton multiple cases:
     the reason for using Singleton, Because there's no need to create a new object for each request, which wastes both CPU and memory;
    uses multiple cases to prevent concurrency problems, where one request alters the state of an object, and the object processes another request. The previous change in the state of the object caused the object to handle the error of the other request;
     with Singleton and multi-instance criteria has only one:
     When the object contains a state that can be changed (more precisely in the actual application, the state will change), then multiple cases, or a single example;
4.  when to use a singleton? When to use multiple cases?
     for struts2, the action must be in multiple cases, because the action itself contains the value of the requested parameter and can be changed;
   for STRUTS1, The action is available as a singleton, because the value of the request parameter is placed in the Actionform, not the action;
    Another thing to say is that the service or DAO must be a singleton, the standard with the 3rd, It has been seen that the service also contains a change in the state, while the execution method also relies on the state, but the same as the singleton, so that there will be hidden bugs, and the concurrency of the bug is often difficult to reproduce and find;

Singleton multiple cases

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.