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