Embodiment
The embodiment of the invention provides a kind of mthods, systems and devices of data sharing, effectively to guarantee dirty data can not occur under the fully shared prerequisite of single call data.
In order can not influence under the conforming prerequisite of business semantics, abundant shared service data, improve the performance of data access and solve data consistency and ageing problem, the embodiment of the invention has proposed a kind of based on the shared method of thread data in buffer, by tape spare control, be kept at the interim buffer memory in the thread, under the prerequisite that does not change business logic codes, guarantee the high-performance of using.
As shown in Figure 1, the system applies environment for the embodiment of the invention comprises:
Condition controller 1, be positioned at before the data access controller, tackled and used the true visit of API to data, coming control data by built-in condition steering logic is directly to obtain from database or obtain from buffer memory by the thread buffer memory by the data access device;
Thread buffer memory 2, itself and thread are bound, the life cycle of thread buffer memory can equal the life cycle of thread, also can be less than the life cycle of thread, avoid occurring dirty data, be mainly used in to described condition controller the Query Result data are provided, when the data access controller when the condition controller returns the Query Result data, the described Query Result data of typing, once request generally binds together with a thread in application system, after a Request Processing is finished, in order to prevent dirty data to occur when memory overflow and thread from sharing, need be with the data cached removing of thread;
Data access controller 3 is used to provide the encapsulation to database access, is data access layer common in the application system;
Database 4 refers to store the system of data, refers generally to the relation data library storage, other storage medium storehouses such as general reference text, multimedia.
When using API or other devices when described condition controller 1 sends the data query request, described condition controller 1 need to judge whether the described thread buffer memory 2 of visit.Judged result is when needing visit thread buffer memory 2, to send query requests to described thread buffer memory 2; After receiving the Query Result data that described thread buffer memory 2 returns, return described Query Result data.Judged result is not when needing to visit thread buffer memory 2, condition controller 1 sends the data query request to data access controller 3, data access controller 3 is searched for corresponding data according to the data query request in database 4, and the Query Result data are returned to condition controller 1.Condition controller 1 returns the Query Result data.
The methods, devices and systems of the data sharing that the embodiment of the invention is provided below in conjunction with the drawings and specific embodiments are elaborated.
The process flow diagram of the method for the data sharing that Fig. 2 provides for the embodiment of the invention comprises:
Step S201, receive the data query request, judge whether to visit the thread buffer memory.
Concrete, buffer memory and thread can be bound, form the thread buffer memory.And the life cycle of the thread variable sign buffer memory of use thread, make its life cycle consistent with thread.After receiving the data query request, according to the condition steering logic of setting to data query request judge.The way of realization of described condition steering logic can be a series of Rule of judgment.
Step S202, described judged result send query requests to described thread buffer memory during for the described thread buffer memory of visit.
Concrete, judged result is when needing visit thread buffer memory, to send query requests to the thread buffer memory; Judged result sends the data query request to the data access controller when not needing to visit the thread buffer memory, and receives the Query Result data that the data access controller obtains from database.
Can judge whether receive the Query Result data needs typing thread buffer memory, and return described Query Result data to the transmit leg of described data query request.Can whether needs typing thread buffer memory be judged to described Query Result data according to inner corresponding configuration.
Step S203, receive the Query Result data that described thread buffer memory returns, return described Query Result data to the transmit leg of described data query request.
Concrete, receive the Query Result data that the thread buffer memory returns after, can judge whether the Query Result data effective.For example, when thread buffer memory return data was empty, data were invalid; After perhaps the number of times inquired about of the data of being inquired about surpassed threshold value, these data were invalid.After judging that the Query Result data effectively, return described Query Result data to the transmit leg of described data query request.Judge when the Query Result data are invalid, need send the data query request to the data qualification controller.
After receiving the data query request, at first judge whether to visit the thread buffer memory,, can directly from the thread buffer memory, obtain the Query Result data if judgement needs visit thread buffer memory, can effectively guarantee so can not occur under the prerequisite of dirty data, make the single call data fully shared.
Below by embodiment the method for data sharing provided by the invention is elaborated, as shown in Figure 3, specifically comprises:
Step S301, application API initiate data access in inside to database.
Concrete, the application interface that described application API general reference designs in order to finish business operation has comprised one or more atomic function usually, as user's verification, flow process control.For using API, its main target is to finish a certain specific function, needs accessing database generally speaking in order to finish described specific function.
Step S302, application API send the data query request to the condition controller.
Step S303, condition controller inquiry self interior condition steering logic need to judge whether visit thread buffer memory.
Concrete, described condition controller is controlled the position that obtains of data query by built-in condition steering logic, that is to say that the control data query is directly to obtain from database, still obtains from buffer memory by the thread buffer memory.We can say that also the condition controller is an intermediate controlled assembly of using API and database, all-access is all transmitted through the condition controller.
The condition steering logic implementation of described condition controller is a series of condition judgment, and can utilize database, decision table or other modes to realize.These Rule of judgment can be fixed on condition controller inside.For example the condition steering logic can be set at: be designated the inquiry of the SQL of x to the inquiry of certain entity A or to the inquiry of certain SQL (Structure Query Language, Structured Query Language (SQL)) or to certain.
According to the actual needs, described condition steering logic can be set at and come into force sometime, also can be set at sometime the section come into force.For example need safeguard database, can set thread and be buffered in this time period and come into force in certain time period.
Step S304, condition controller judge whether needs access cache of data query request according to the condition steering logic, and judged result is during for needs, execution in step S305; Otherwise, execution in step S308.
Concrete, during condition steering logic in the data query request satisfies condition controller, being judged as needs access cache; Otherwise being judged as does not need access cache.
Step S305, condition controller send the data query request to the thread buffer memory.
Described thread buffer memory is actually the buffer memory of the transient state that is positioned at a threads store inside, and inside is the mapping of key assignments and object.Concrete, the SQL that has special parameter determines that has a uniquely identified key assignments, this key-value pair should unique object.That is to say that described key assignments can be used to identify the uniqueness of Query Result data.The way of realization of the described SQL that has a special parameter can be the name of SQL and parameter, SQL and parameter etc.
Step S306, thread buffer memory return the Query Result data to the condition controller.
Step S307, condition controller judge whether the Query Result data that the thread buffer memory returns are effective.
Concrete, data effectively can index according to existing or in the data term of validity, satisfying certain regulation.For example, when thread buffer memory return data was empty, data were invalid; After perhaps the number of times inquired about of the data of being inquired about surpassed threshold value, these data were invalid.Certainly, the judgment data effective and efficient manner is not limited to above-described mode in actual conditions.
Judge that the Query Result data are effective, execution in step S314; Otherwise, execution in step S308.
Step S308, condition controller send the data query request to the data access controller.
Concrete, the condition controller judges that according to the condition steering logic data query request during needs visit thread buffer memory, sends the data query request to the data access controller.
Step S309, data access controller are inquired about corresponding data information according to the data query request that the conditional access controller sends in database.
Step S310, database return the Query Result data to the data access controller.
Step S311, data access controller send to the condition controller with the Query Result data that database returns.
Step S312, condition controller judge whether the Query Result data need typing thread buffer memory.If desired, execution in step S313; Otherwise, direct execution in step S314.
Concrete, can be according to the configuration determination of condition controller needs typing thread buffer memory whether, meet configuration requirement and can think needs typing thread buffer memory.
The typing thread buffer memory that needs described here comprises two implications: the one, at first from the thread buffer memory, search during data query; The 2nd, the Query Result data of inquiring about (do not find data in the thread buffer memory and use the data access controller to obtain data) first will be saved in the thread buffer memory.
Step S313, with Query Result data typing thread buffer memory.
Step S314, the Query Result data are returned to use API.
Step S315, application API send the ending request that this request of expression finishes to the condition controller.
After step S316, condition controller receive the ending request of using the API transmission, destroy cache object and buffer memory self in the thread buffer memory, and cleaning thread variable, flow process finishes.
Visit the thread buffer memory and obtain corresponding data query route by judging whether, and obtain the Query Result data, can improve the performance of data access keeping using under the consistance prerequisite of API semanteme according to judged result.
The embodiment of the invention is an example with the order in the management-type application system, and a kind of method of data sharing is provided, and can improve the performance of data access.
Whether whether a large amount of application API imports as using API with Subscriber Number in the order flow process, for example judge whether the user exists, allow the product that the user orders, the user orders to exist mutex relation (promptly ordered a product and just can not order another product), user whether to repeat to have ordered certain product with existing product.
Problem is supposed to order calling function A, function merit B, function C and function D successively for convenience of explanation, and function described here is just used API.Using API can be a concrete business function interface, can be implemented as a method, as the function of C++, the method for Java, perhaps can be implemented as component interface, as the interface of an EJB (Enterprise JavaBean) etc.Here be embodied as example with the Java method, the scene synoptic diagram has been listed the internal request that need carry out data access as shown in Figure 4 in each function, only listed the data access request that a plurality of functions repeat to call for the sake of simplicity here.
Function A, function B, function C and function D all need by Subscriber Number inquiring user key assignments, and wherein function C and function D all need by user's key assignments inquiring user existing products order record.
Set forth how to realize data shared access below in conjunction with concrete flow process based on the thread buffer memory.
Sight one: function A call flow;
During product subscription at first calling function A judge whether the user exists, need " according to Subscriber Number inquiring user key assignments " among the function A, as shown in Figure 5, comprising:
Step S501, function A send the data query request to the condition controller.
Concrete, the way of realization of request adds relevant parameter for the SQL (Structured Query Language (SQL)) of band name, and wherein each SQL all identifies by a title, and described relevant parameter is a Subscriber Number.
Step S502, condition controller inquiry interior condition steering logic need to judge whether visit thread buffer memory.
The mode of condition controller service regeulations engine realizes, described regulation engine is developed by inference engine, be a kind of assembly that is embedded in the application program, can realize operational decision making is separated from application code, and use predefined semantic module to write operational decision making.Utilize regulation engine definite condition steering logic herein.
Ios dhcp sample configuration IOS DHCP for condition controller in the present embodiment is as follows:
The information of IF inquiring user
THEN uses the thread buffer memory
Send to the query requests of condition controller for function A, because inquiry is user profile, above-mentioned condition judgment is set up, and the condition controller of that is to say is judged " according to Subscriber Number inquiring user key assignments " needs access cache.
Step S503, condition controller send the data query request to the thread buffer memory.
The thread buffer memory uses the thread variable of binding with thread herein, in the thread with the Java language structure thread variable can be set, and expression buffer memory life cycle is consistent with thread.Preserve a Hash table in the thread variable, the condition controller sends the Hash key assignments to the thread buffer memory, and key assignments is the Hash codes that has SQL title and parameter.Utilize key assignments in the thread buffer memory, to inquire about corresponding data.
Step S504, thread buffer memory return the Query Result data to the condition controller.
If do not inquire corresponding Query Result data in the thread buffer memory, the data that the thread buffer memory returns are for empty, and these Query Result data are invalid, continue execution in step S505.In this embodiment, there are not corresponding data in the thread buffer memory.
Step S505, condition controller send the data query request to the data access controller.
Concrete, the condition controller sends the data query request to the data access controller, and according to the Subscriber Number inquiring user key assignments in the query requests, data access controller way of realization is the data access encapsulation of JDBC here.
Described JDBC (Java Data Base Connectivity, the java database connects) is a kind of Java API that is used to carry out SQL statement, can provide unified visit for multiple relational database, and it is made up of one group of class and interface of writing with Java language.
Step S506, data access controller be according to Subscriber Number, the key assignments of inquiring user in the directory of database.
Step S507, database turn back to the data access controller with user's key assignments.
Step S508, data access controller return to the condition controller with user's key assignments.
Step S509, with user's key assignments typing buffer memory.
Can judge these Query Result data by the configuration of condition controller among the step S502 needs typing thread buffer memory, so continue to carry out following steps.
Step S510, condition controller turn back to function A with user's key assignments.
Sight two: function B call flow;
Product subscription calling function B judges " whether allowing the user to order ", needs " according to Subscriber Number inquiring user key assignments " among the function B.As shown in Figure 6, comprising:
Step S601, function B send the data query request to the condition controller.
Step S602, condition controller are according to the condition steering logic of inside needs inquiry thread buffer memory whether.
Because the ios dhcp sample configuration IOS DHCP of condition controller is as follows:
The information of IF inquiring user
THEN uses the thread buffer memory
So judging needs inquiry thread buffer memory.The condition controller continues to carry out following steps after judging and needing visit thread buffer memory;
Step S603, condition controller send the data query request to the thread buffer memory.
Step S604, thread buffer memory return to the condition controller with the Query Result data.
Because function A is entered into the relevant query result data in the thread buffer memory before this, the thread buffer memory can directly return the Query Result data to the condition controller.
Step S605, condition controller return to function B with the user's key assignments that inquires.
The call flow of the flow process of " according to Subscriber Number inquiring user key assignments " and function B is similar among function C, the function D.
" according to user's key assignments inquiry existing procucts order record " is similar with the flow process of function A among the function C, needs accessing database for the first time during data query; The flow process and the function B call flow of " according to user's key assignments inquiry existing procucts order record " are similar among the function D, can directly obtain data from the thread buffer memory.
After subscription process was finished, application API sent ending request and represents that this request finishes for the condition controller, cache object and buffer memory self during condition controller destruction thread delays, and cleaning thread variable, and thread buffer memory life cycle finishes.
The data sharing method that the application of the invention embodiment provides can reduce the number of times of accessing database keeping using under consistance (as only using C++, the Java) prerequisite of API semanteme, improves the performance of data access.
Simultaneously, the embodiment of the invention also provides a kind of device of data sharing, as shown in Figure 7, specifically comprises:
First receiver module 10 is used to receive the data query request;
First judge module 20 is used for judging whether to visit the thread buffer memory when described first receiver module 10 receives the data query request;
First sending module 30 is used for sending query requests to described thread buffer memory when described first judge module 20 is judged visit thread buffer memory;
Second receiver module 40 is used to receive the Query Result data that described thread buffer memory returns;
Second sending module 50 is used for when described second receiver module 40 receives the Query Result data, returns described Query Result data to the transmit leg of described data query request.
By above-described device, can realize data sharing, specific implementation is as follows:
After first receiver module 10 received the data query request, first judge module 20 judged whether this request needs to visit the thread buffer memory.When 20 judgements of first judge module needed visit thread buffer memory, first sending module 30 sent query requests to described thread buffer memory.
Second receiver module 40 receives the Query Result data that described thread buffer memory returns according to query requests, returns described Query Result data by second sending module 50 to the transmit leg of described data query request then.
As shown in Figure 8, the device of described data sharing in another embodiment can also comprise:
The 3rd sending module 60 is used for sending query requests to the data access controller when the thread buffer memory is not visited in 20 judgements of described first judge module;
The 3rd receiver module 70 is used to receive the Query Result data that described data access controller returns;
The 4th sending module 80 is used for when described the 3rd receiver module 70 receives the Query Result data, returns described Query Result data to the transmit leg of described data query request.
The device of described data sharing in another embodiment can also comprise:
Second judge module 90 is used to judge whether the Query Result data of described second receiver module 40 receptions are effective;
Typing judge module 100 is used to judge whether typing thread buffer memory of Query Result data that described the 3rd receiver module 70 receives.
The device of described data sharing can also comprise:
Destroy module 110, be used for receiving object and the buffer memory self of destroying the thread buffer memory after the ending request and also clear up the thread variable.
By above-described module, can realize data sharing, specific implementation is as follows:
After first receiver module 10 received the data query request, first judge module 20 judged whether this request needs to visit the thread buffer memory.Concrete, according to the condition steering logic of setting in first judge module 20 to data query request judge.The way of realization of described condition steering logic is a series of Rule of judgment.
When 20 judgements of first judge module needed visit thread buffer memory, first sending module 30 sent query requests to described thread buffer memory.After second receiver module 40 receives the Query Result data that described thread buffer memory returns according to query requests, whether the Query Result data that second judge module 90 detects 40 receptions of described second receiver module are effective, if effectively, the Query Result data are sent to application interface by second sending module 50; If invalid, send query requests to the data access controller by the 3rd sending module 60.
When 20 judgements of first judge module did not need to visit the thread buffer memory, the 3rd sending module 60 sent query requests to the data access controller.After the 3rd receiver module 70 received the Query Result data that described data access controller returns, typing judge module 100 judged whether the Query Result data need typing thread buffer memory.After this 4th sending module 80 returns the Query Result data to application interface.
After receiving ending request, object and the buffer memory self destroyed in the module 110 destruction thread buffer memorys are also cleared up the thread variable.
The device of the data sharing that the application of the invention embodiment provides can be realized the method for data sharing, has effectively guaranteed can not occur under the prerequisite of dirty data, makes the single call data fully shared.
The embodiment of the invention also provides a kind of system of data sharing simultaneously, as shown in Figure 1, comprising: condition controller 1, thread buffer memory 2;
Described condition controller 1 is used to receive the data query request, need to judge whether the described thread buffer memory of visit; Described judged result is when needing visit thread buffer memory, to send query requests to described thread buffer memory; Receive the Query Result data that described thread buffer memory returns, return described Query Result data to the transmit leg of described data query request;
Described thread buffer memory 2 is used to described condition controller 1 that the Query Result data are provided, when the data access controller when the condition controller returns the Query Result data, the described Query Result data of typing.
The system of described data sharing also comprises: data access controller 3 and database 4;
Described data access controller 3, be used to receive the data query request that condition controller 2 sends after, data query and the Query Result data are sent to the condition controller in database;
Described database 4 is used to described data access controller 3 that data query is provided.
Concrete, described condition controller 1 receives the data query request, need to judge whether the described thread buffer memory 2 of visit; Described judged result is when needing visit thread buffer memory, to send query requests to described thread buffer memory 2; After receiving the Query Result data that described thread buffer memory 2 returns, return described Query Result data to the transmit leg of described data query request.Described judged result is not when needing to visit thread buffer memory 2, condition controller 1 sends the data query request to data access controller 3, described data access controller 3 is searched for corresponding data according to the data query request in database 4, and the Query Result data are returned condition controller 1.Condition controller 1 returns described Query Result data to the transmit leg of described data query request.
Described condition controller comprises:
First receiver module 10 is used to receive the data query request;
First judge module 20 is used for judging whether to visit the thread buffer memory when described first receiver module 10 receives the data query request;
First sending module 30 is used for sending query requests to described thread buffer memory when described first judge module 20 is judged visit thread buffer memory;
Second receiver module 40 is used to receive the Query Result data that described thread buffer memory returns;
Second sending module 50 is used for when described second receiver module 40 receives the Query Result data, returns described Query Result data to the transmit leg of described data query request.
By the above module, can realize data sharing, specific implementation is as follows:
After first receiver module 10 received the data query request, first judge module 20 judged whether this request needs to visit the thread buffer memory.When 20 judgements of first judge module needed visit thread buffer memory, first sending module 30 sent query requests to described thread buffer memory.
Second receiver module 40 receives the Query Result data that described thread buffer memory returns according to query requests, returns described Query Result data by second sending module 50 to the transmit leg of described data query request then.
Described condition controller also comprises:
The 3rd sending module 60 is used for sending query requests to the data access controller when the thread buffer memory is not visited in 20 judgements of described first judge module;
The 3rd receiver module 70 is used to receive the Query Result data that described data access controller returns;
The 4th sending module 80 is used for when described the 3rd receiver module 70 receives the Query Result data, returns described Query Result data to the transmit leg of described data query request.
Described condition controller also comprises:
Second judge module 90 is used to judge whether the Query Result data of described second receiver module 40 receptions are effective;
Typing judge module 100 is used to judge whether typing thread buffer memory of Query Result data that described the 3rd receiver module 70 receives.
Described condition controller also comprises:
Destroy module 110, be used for receiving object and the buffer memory self of destroying the thread buffer memory after the ending request and also clear up the thread variable.
By the above module, can realize data sharing, specific implementation is as follows:
After first receiver module 10 received the data query request, first judge module 20 judged whether this request needs to visit thread buffer memory 2.Concrete, according to the condition steering logic of setting in first judge module 20 to data query request judge.The way of realization of described condition steering logic is a series of Rule of judgment.
When 20 judgements of first judge module needed visit thread buffer memory 2, first sending module 30 sent query requests to described thread buffer memory 2.After second receiver module 40 receives the Query Result data that described thread buffer memory 2 returns according to query requests, whether the Query Result data that second judge module 90 detects 40 receptions of described second receiver module are effective, if effectively, the Query Result data are sent to application interface by second sending module 50; If invalid, send query requests to data access controller 3 by the 3rd sending module 60.
When 20 judgements of first judge module did not need to visit the thread buffer memory, the 3rd sending module 60 sent query requests to data access controller 3.Data access controller 3 obtains corresponding data in database 4.After the 3rd receiver module 70 received the Query Result data that described data access controller 3 returns, typing judge module 100 judged whether the Query Result data need typing thread buffer memory 2.After this 4th sending module 80 returns the Query Result data to application interface.
After receiving ending request, object and the buffer memory self destroyed in the module 110 destruction thread buffer memorys are also cleared up the thread variable.
The mthods, systems and devices that the embodiment of the application of the invention provides, can effectively guarantee can not occur under the prerequisite of dirty data, make the single call data fully shared, and, improve the performance of data access keeping using under the consistance prerequisite of API semanteme.
Through the above description of the embodiments, those skilled in the art can be well understood to the present invention and can realize by hardware, also can realize based on such understanding by the mode that software adds necessary general hardware platform, technical scheme of the present invention can embody with the form of software product, it (can be CD-ROM that this software product can be stored in a non-volatile memory medium, USB flash disk, portable hard drive etc.) in, comprise that some instructions are with so that a computer equipment (can be a personal computer, server, the perhaps network equipment etc.) carry out the described method of each embodiment of the present invention.
More than disclosed only be several specific embodiment of the present invention, still, the present invention is not limited thereto, any those skilled in the art can think variation all should fall into protection scope of the present invention.