What is the role of Singleton mode in database connection?

Source: Internet
Author: User
Isn't this a small limit on the number of connections? Isn't it a small limit on the number of connections?

Reply content:

Isn't this limiting the number of connections very small?

The Singleton mode ensures that there is only one instance in a class in the system and the instance is easy to access, so as to conveniently control the number of instances and save system resources. For the landlord, the singleton ensures that the connection class of the database driver is initialized only once (not the number of connections to the database), so that subsequent requests use the same connection instance, this is certainly okay when the concurrency is not large. When the concurrency is very large, it is easy to cause a thread to use this connection and never release it, and the subsequent threads cannot be used. This must be a problem, we usually create a connection pool, such as creating 20 connection pools. Depends on the actual situation.

You do not need to repeatedly disconnect, initiate, disconnect, initiate, or initiate a connection, disconnect, initiate, disconnect, initiate, and disconnect, initiate a connection, disconnect a connection, initiate a connection, disconnect a connection, initiate a connection, initiate a connection, disconnect a connection, and initiate a connection, disconnect, initiate, disconnect, initiate, and disconnect, initiate a connection, disconnect a connection, initiate a connection, disconnect a connection, initiate a connection, disconnect a connection, and initiate a connection.

A singleton ensures that a class has only one instance and has no direct relationship with the database connection.

Reuse. If it is used for Link Management, a program can basically have only one database link.

The Singleton mode is not used. You have created a new database many times, which occupies a lot of memory.

The processes requested by each runner are different, and not everyone you understand is using a ready-to-use database operation.

The Singleton mode ensures that the database class is instantiated only once to reduce memory usage.

Simply put: Resource Reuse

Below are the comments of a singleton in the project.

// Make all cluster connections use the same connection so that all operations can be performed in the same transaction

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.