Home > Java > javaTutorial > What is singleton pattern in java

What is singleton pattern in java

little bottle
Release: 2020-09-18 09:59:05
Original
6402 people have browsed it

java singleton mode is a common design pattern. The singleton mode ensures that a certain class has only one instance, instantiates itself and provides this instance to the entire system. The singleton mode is divided into "lazy singleton". There are three types: "example", "hungry-style single case", and "registered single case".

What is singleton pattern in java

#The singleton pattern is a common design pattern in Java design. The main content of this article is to introduce the singleton pattern in Java.

java singleton pattern is a common design pattern.

There are three types of singleton modes: lazy-style singleton, hungry-style singleton, and registration-style singleton.

The singleton mode has the following characteristics:
 1. A singleton class can only have one instance.
 2. The singleton class must create its own unique instance.
 3. The singleton class must provide this instance to all other objects.
The singleton mode ensures that a class has only one instance, and it instantiates itself and provides this instance to the entire system.

In computer systems, thread pools, caches, log objects, dialog boxes, printers, and graphics card driver objects are often designed as singletons.

These applications all have more or less the function of resource managers. Each computer can have several printers, but there can only be one Printer Spooler to prevent two print jobs from being output to the printer at the same time. Each computer can have several communication ports, and the system should centrally manage these communication ports to prevent one communication port from being called by two requests at the same time. In short, the purpose of choosing the singleton mode is to avoid inconsistent states and avoid long-term policies.

The above is the detailed content of What is singleton pattern in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template