Background technology
Connection data storehouse is at substantial resource and relatively slow operation in application program, but they are again crucial.Connection pool is a container of that opened and reusable DataBase combining.Connection pool just discharges when all DataBase combining are all closed from internal memory.Use the most basic advantage of connection pool to be improve performance and the scalability of application program, and always its major defect has one or more DataBase combining to stay open state, even if current not in use.The DataProviders of ADO.NET will use connection pool by under default situations, if do not want to use connection pool, must specify in connection string " Polling=false ".
Flourish along with internet, database security and the stable favor being more and more subject to everybody, the connected mode of current same domain roughly has:
(1) JDBC database connection pool
Ecosystem database connection pool, does not do any encapsulation to data cube computation, and corresponding developer brings very large complexity, and tempo of development is slow, programming reusability is few.(most of enterprise has done the encapsulation of basic energy to it)
(2) DBCP Data Connection Pool
DBCP (DataBaseconnectionpool), database connection pool.Being a java connection pool project on apache, is also the Pool Component that tomcat uses.Be used alone dbcp and need 3 bag: common-dbcp.jar, common-pool.jar, common-collections.jar is the behavior in a cost source very consuming time because building database connects, so by connection pool, with Database, some connect in advance, be placed in internal memory, in connection pool, directly apply for one when application program needs building database to connect just, put back to again after being finished.
(3)c3p0
C3P0 is a JDBC connection pool of increasing income, and it achieves data source and JNDI binding, supports the standard extension of JDBC3 specification and JDBC2.Its open source projects of current use has Hibernate, Spring etc.
(4) .Net database connection pool
Database connection pool value is generally carry out value line by line, cannot determine the accuracy of data like this, if but improperly use connection pool may bring negative effects to application program, not only improper use connection pool is not useful and is harmful.
Summary of the invention
Object of the present invention is intended at least solve one of described technological deficiency.
For this reason, the object of the invention is to propose a kind of data managing method based on .NET database connection pool and system, there is accurate positioning, promote Consumer's Experience, fast response time, Consumer's Experience speed are fast, secure user data and improve the efficiency of application program and the feature of scalability.
To achieve these goals, the embodiment of one aspect of the present invention provides a kind of data managing method based on .NET database connection pool, performs following steps by .NET wide area information server management system:
The connection string that described data base management system (DBMS) connects according to first time requested database connects pond, and described connection pool comprises the DataBase combining of multiple idle condition;
Described data base management system (DBMS) after receiving the connection request of user, for described connection request creates a thread;
Described thread sends connection application request to described database connection pool;
Described data base management system (DBMS), after the connection application request receiving described thread, searches the DataBase combining of whether available free state from described connection pool, if had, connect to described thread allocation database;
Described thread carries out data call with function corresponding to the connection request performing described user according to the described DataBase combining of described distribution, and wherein, described DataBase combining is according to ranks and the mode of getting carries out value;
Described thread, after the function that complete described connection request is corresponding, discharges described DataBase combining to described connection pool.
Further, described DataBase combining is according to ranks and the mode of getting carries out value, comprising: adopt ranks interleaved mode to carry out value.
Further, described connection pool also comprises: the DataBase combining of open mode and reusable state.
Further, described data base management system (DBMS) detect carry new connection string in described connection application request time, wherein, the connection string that the first time requested database that this new connection string is corresponding from the described connection pool set up connects is different, then set up a new connection pool, and allocation database connects the connection application request carrying new connection string with response from this new connection pool.
Further, also comprise the steps: that described data base management system (DBMS) is when user's inoperation database being detected, discharges DataBase combining automatically.
The present invention's embodiment on the other hand provides a kind of data management system based on .NET database connection pool, comprise: connection pool sets up unit, for the pond that connects according to the connection string of first time requested database connection, described connection pool comprises the DataBase combining of multiple idle condition; Thread creation unit, for after receiving the connection request of user, for described connection request creates a thread; DataBase combining administrative unit, for after the connection application request receiving described thread, searches the DataBase combining of whether available free state from described connection pool, if had, connect to described thread allocation database; Wherein, described thread carries out data call with function corresponding to the connection request performing described user according to the described DataBase combining of described distribution, wherein, described DataBase combining is according to ranks and the mode of getting carries out value, described thread, after the function that complete described connection request is corresponding, discharges described DataBase combining to described connection pool.
Further, described DataBase combining is according to ranks and the mode of getting carries out value, comprising: adopt ranks interleaved mode to carry out value.
Further, described connection pool also comprises: the DataBase combining of open mode and reusable state.
Further, described connection pool set up unit also for detect carry new connection string in the described connection application request from thread time, wherein, the connection string that the first time requested database that this new connection string is corresponding from the described connection pool set up connects is different, then set up a new connection pool, and connect by described DataBase combining administrative unit allocation database from this new connection pool the connection application request carrying new connection string with response.
Further, described DataBase combining administrative unit also for when user's inoperation database being detected, discharges DataBase combining automatically.
According to the data managing method based on .NET database connection pool and the system of the embodiment of the present invention, combine based on JDBC and .net technology and a set of DataBase combining instrument editing out, achieve cross-platform, cross-cutting, its expansion, there is special value mode, common database connection pool value is generally value line by line, the accuracy of such data be can not determine, this sets of data storehouse connection pool not only obtains largest optimization to DataBase combining amount, and the accuracy that special process (ranks are also got) ensures data be have also been made to peek, and can automatic release connection when database does not connect.The present invention can the data that send request of disposable reading user, have accurate positioning, promote Consumer's Experience, fast response time, Consumer's Experience speed are fast, secure user data and improve the efficiency of application program and the feature of scalability.
The aspect that the present invention adds and advantage will part provide in the following description, and part will become obvious from the following description, or be recognized by practice of the present invention.
Embodiment
Be described below in detail embodiments of the invention, the example of described embodiment is shown in the drawings, and wherein same or similar label represents same or similar element or has element that is identical or similar functions from start to finish.Be exemplary below by the embodiment be described with reference to the drawings, be intended to for explaining the present invention, and can not limitation of the present invention be interpreted as.
As shown in Figure 1, the data managing method based on .NET database connection pool of the embodiment of the present invention performs following steps by .NET wide area information server management system:
Step S1, the connection string that data base management system (DBMS) connects according to first time requested database connects pond.
Particularly, connection pool is created by a unique connection string.In this step, data base management system (DBMS) is the connection pool that the connection string connected according to first time requested database creates.Wherein, connection pool comprises the DataBase combining of multiple idle condition.In addition, connection pool can also comprise: the DataBase combining of open mode and reusable state.
It should be noted that can there be multiple connection pool in synchronization same application territory, but connection pool cannot be shared across Application Domain.When the connection string requested database that another one is different connects, another connection pool will be created.Therefore a corresponding connection pool instead of a corresponding connection pool of database in a concatenation character.
In one embodiment of the invention, data base management system (DBMS) detect in connection application request carry new connection string time, wherein, the connection string that the first time requested database that this new connection string is corresponding from the connection pool set up connects is different, then set up a new connection pool, and allocation database connects the connection application request carrying new connection string with response from this new connection pool.
In other words, the connection pool of .Net database is the container of database connection object, if wherein existence activity or the connection of opening its maintain active state.When use connection string carrys out requested database connection, by connection pool new for distribution one.By using identical connection string in the application, performance and the scalability of application program can be improved.
Step S2, data base management system (DBMS) after receiving the connection request of user, for this connection request creates a thread.
Fig. 2 is the schematic diagram of the data managing method based on .NET database connection pool according to the embodiment of the present invention.
As shown in Figure 2, data base management system (DBMS) can receive the connection request of one or more user, the connection request of such as, two users in Fig. 2.Data base management system (DBMS), according to the connection request receiving two users (user 1 and user 2), is respectively each connection request and creates a thread, be i.e. thread 1 and thread 2.
Step S3, thread sends connection application request to database connection pool.
With reference to figure 2, thread 1 and thread 2, respectively according to the connection request of respective respective user, send connection application request to database connection pool, to apply for connecting.
Step S4, data base management system (DBMS), after the connection application request receiving thread, is searched the DataBase combining of whether available free state, if had, is connected to thread allocation database from connection pool.
In this step, DataBase combining, after the DataBase combining finding available free state in connection pool, is distributed to each thread by data base management system (DBMS).
Step S5, thread carries out data call with function corresponding to the connection request performing user according to the DataBase combining distributed.
In this step, each thread utilizes data base management system (DBMS) to the DataBase combining distributed separately, performs the function that the connection request of respective user is corresponding.
In one embodiment of the invention, DataBase combining is according to ranks and the mode of getting carries out value.Particularly, DataBase combining is according to ranks and the mode of getting carries out value, comprising: adopt ranks interleaved mode to carry out value.This reading data mode can realize, to the accurate reading of data, guaranteeing not obliterated data.
Step S6, thread is after the function that complete connection request is corresponding, and release DataBase combining is to connection pool.
In yet another embodiment of the present invention, data base management system (DBMS), when user's inoperation database being detected, discharges DataBase combining automatically.
As shown in Figure 3, the embodiment of the present invention also proposes a kind of data management system based on .NET database connection pool, comprising: connection pool sets up unit 1, thread creation unit 2 and DataBase combining administrative unit 3.
Particularly, connection pool sets up unit 1 for the pond that connects according to the connection string of first time requested database connection.
Connection pool is created by a unique connection string.In this step, data base management system (DBMS) is the connection pool that the connection string connected according to first time requested database creates.Wherein, connection pool comprises the DataBase combining of multiple idle condition.Further, connection pool also comprises: the DataBase combining of open mode and reusable state.
It should be noted that can there be multiple connection pool in synchronization same application territory, but connection pool cannot be shared across Application Domain.When the connection string requested database that another one is different connects, another connection pool will be created.Therefore a corresponding connection pool instead of a corresponding connection pool of database in a concatenation character.
In one embodiment of the invention, connection pool set up unit 1 detect in connection application request carry new connection string time, wherein, the connection string that the first time requested database that this new connection string is corresponding from the connection pool set up connects is different, then set up a new connection pool, and allocation database connects the connection application request carrying new connection string with response from this new connection pool.
In other words, the connection pool of .Net database is the container of database connection object, if wherein existence activity or the connection of opening its maintain active state.When use connection string carrys out requested database connection, by connection pool new for distribution one.By using identical connection string in the application, performance and the scalability of application program can be improved.
Thread creation unit 2 for after receiving the connection request of user, for connection request creates a thread.
Particularly, thread creation unit 2 can receive the connection request of one or more user, the connection request of such as, two users in Fig. 2.Data base management system (DBMS), according to the connection request receiving user, is respectively each connection request and creates a thread.Each thread, respectively according to the connection request of respective respective user, sends connection application request to DataBase combining administrative unit 3, to apply for connecting.
DataBase combining administrative unit 3, for after the connection application request receiving thread, is searched the DataBase combining of whether available free state, if had, is connected to thread allocation database from connection pool.
Each thread utilizes data base management system (DBMS) to the DataBase combining distributed separately, performs the function that the connection request of respective user is corresponding.
In one embodiment of the invention, DataBase combining is according to ranks and the mode of getting carries out value.Particularly, DataBase combining is according to ranks and the mode of getting carries out value, comprising: adopt ranks interleaved mode to carry out value.This reading data mode can realize, to the accurate reading of data, guaranteeing not obliterated data.
Thread is after the function that complete connection request is corresponding, and release DataBase combining is to connection pool.In one embodiment of the invention, DataBase combining administrative unit 3 also for when user's inoperation database being detected, discharges DataBase combining automatically.
To sum up, connection pool provides the idle reusable DataBase combining opened, and no longer needs to open a DataBase combining request msg database data is stylish at every turn.When DataBase combining close or release time, will turn back in connection pool, and again keep idle condition until new connection request arrives, effectively use connection pool, opening and closing database will no longer very consumes resources, the efficiency of raising application program and scalability.
According to the data managing method based on .NET database connection pool and the system of the embodiment of the present invention, combine based on JDBC and .net technology and a set of DataBase combining instrument editing out, achieve cross-platform, cross-cutting, its expansion, there is special value mode, common database connection pool value is generally value line by line, the accuracy of such data be can not determine, this sets of data storehouse connection pool not only obtains largest optimization to DataBase combining amount, and the accuracy that special process (ranks are also got) ensures data be have also been made to peek, and can automatic release connection when database does not connect.The present invention can the data that send request of disposable reading user, have accurate positioning, promote Consumer's Experience, fast response time, Consumer's Experience speed are fast, secure user data and improve the efficiency of application program and the feature of scalability.
In the description of this instructions, specific features, structure, material or feature that the description of reference term " embodiment ", " some embodiments ", " example ", " concrete example " or " some examples " etc. means to describe in conjunction with this embodiment or example are contained at least one embodiment of the present invention or example.In this manual, identical embodiment or example are not necessarily referred to the schematic representation of above-mentioned term.And the specific features of description, structure, material or feature can combine in an appropriate manner in any one or more embodiment or example.
Although illustrate and describe embodiments of the invention above, be understandable that, above-described embodiment is exemplary, can not be interpreted as limitation of the present invention, those of ordinary skill in the art can change above-described embodiment within the scope of the invention when not departing from principle of the present invention and aim, revising, replacing and modification.Scope of the present invention is by claims extremely equivalency.