What is a singleton?
The so-called singleton means that all requests are processed with an object. For example, our commonly used service and dao layer objects are usually singletons.
(Video tutorial recommendation:java video)
Why use a singleton?
1. It is because there is no need to create a new object for every request, which wastes both CPU and memory;
2. It is to prevent concurrency problems; that is, one request changes the object status, at this time the object processes another request, and the previous request's change to the object's status caused the object to incorrectly handle another request;
Recommended tutorial:Getting Started with Java Development
The above is the detailed content of What is a singleton in javaweb. For more information, please follow other related articles on the PHP Chinese website!