What is the role of singleton mode in database connection?

Source: Internet
Author: User
Isn't that a small limit to the number of connections?

Reply content:

Isn't that a small limit to the number of connections?

The singleton mode can guarantee that there is only one instance of a class in the system, and the instance is easy to be accessed, thus it is convenient to control the number of instances and save system resources. According to the landlord, the Singleton ensures that the database-driven connection class is initialized only once (not the number of connections to the database), so that subsequent requests use the same connection instance, which is certainly not a problem when the concurrency is not very large. For a large amount of concurrency, it is easy to cause a thread to use this connection, and then never release, the subsequent threads are not available, this must be problematic, usually we will make a connection pool, such as creating 20 connection pool and so on. Depending on the situation.

No repeated disconnection, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, initiating a connection, disconnecting, Initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, Initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection, disconnect, initiate connection.

A singleton is to make sure that a class has only one instance, and that the database connection is not directly related.

Reuse, if used to do the link management class, basically can be done in a program only a database link.

No singleton mode, database query many times you have new a lot of times, so it takes up memory.

Every flow request process is different, not everyone you understand is using a ready-made database operation

Singleton mode ensures that the database class is instantiated only once to reduce memory consumption

A concise saying: resource reuse

The following is a comment for a single example in the project.

Make all cluster connections use the same connection, so that all operations can be 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.