Summary of the invention
For overcoming Problems existing in correlation technique, the invention provides a kind of method for processing business and device.
According to the first aspect of the embodiment of the present invention, a kind of method for processing business is provided, comprises:
In business procession, store the contextual information of the worker thread sending far call request, and identify for this contextual information distributes contextual information, and this contextual information and this contextual information mark are bound;
This far call request and this contextual information mark are sent to given server, make this far call request of this given server process and return the result of this far call request, this result carries this contextual information mark;
Receive this result, and according to the binding relationship that the contextual information that this result is carried identifies and prestores, obtain and identify with this contextual information the contextual information bound;
Identify according to this contextual information the contextual information and this result bound, carry out this business procession.
In the first possibility implementation of a first aspect of the present invention, before this storage sends the contextual information of the worker thread of far call request, the method also comprises:
When capturing far call request, registered callbacks function, this call back function is used for when getting the result of this far call request, carries out Business Processing according to this result;
After storing the contextual information of the worker thread sending far call request, the method also comprises:
This far call request is stored to designated storage area;
Before this far call request and this contextual information mark are sent to given server, the method also comprises:
This far call request is read from this designated storage area.
In the second possibility implementation of a first aspect of the present invention, after this far call request is stored to designated storage area, the method also comprises:
Discharge the worker thread of this transmission far call request, the worker thread after release is put back to thread pool.
In the third possibility implementation of a first aspect of the present invention, this far call request and this contextual information mark are sent to given server and comprise: by transmission control protocol TCP passage, this far call request and this contextual information mark are sent to given server.
In the 4th kind of possibility implementation of a first aspect of the present invention, this business procession is asynchronous process process.
According to the second aspect of the embodiment of the present invention, a kind of business processing device is provided, comprises:
First processing module, in business procession, stores the contextual information of the worker thread sending far call request, and identifies for this contextual information distributes contextual information, and this contextual information and this contextual information mark is bound;
Sending module, for being that this contextual information mark that this contextual information distributes is sent to given server by this far call request and this first processing module, make this far call request of this given server process and return the result of this far call request, this result carries this contextual information mark;
Receiver module, for receiving this result, and according to the binding relationship that the contextual information that this result is carried identifies and prestores, obtains and identifies with this contextual information the contextual information bound;
Second processing module, for identifying according to this contextual information the contextual information and this result bound, carries out this business procession.
In the first possibility implementation of a second aspect of the present invention, this first processing module is also for when capturing far call request, registered callbacks function, this call back function is used for when getting the result of this far call request, carries out Business Processing according to this result;
This device also comprises:
Memory module, for being stored to designated storage area by this far call request;
Read module, for reading this far call request from this designated storage area.
In the second possibility implementation of a second aspect of the present invention, this device also comprises:
Thread release module, for discharging the worker thread of this transmission far call request, puts back to thread pool by the worker thread after release.
In the third possibility implementation of a second aspect of the present invention, this sending module is used for: by transmission control protocol TCP passage, this far call request and this contextual information mark are sent to given server.
In the 4th kind of possibility implementation of a second aspect of the present invention, this business procession is asynchronous process process.
The beneficial effect that the technical scheme that the embodiment of the present invention provides is brought is:
The present invention is by preserving the contextual information of thread, and identify for this contextual information distributes contextual information, and this contextual information is bound, when sending far call request to given server, send this contextual information mark simultaneously, when given server returns the result of this far call request, return this contextual information mark simultaneously, make server can obtain contextual information according to this contextual information mark and binding relationship, to proceed Business Processing, said method can avoid being in wait state at far call request processing procedure thread cannot be recovered utilization, and then the problem of thread block can be avoided.
Should be understood that, it is only exemplary and explanatory that above general description and details hereinafter describe, and can not limit the present invention.
Embodiment
For making the object, technical solutions and advantages of the present invention clearly, below in conjunction with accompanying drawing, embodiment of the present invention is described further in detail.
Here will be described exemplary embodiment in detail, its sample table shows in the accompanying drawings.When description below relates to accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawing represents same or analogous key element.Execution mode described in following exemplary embodiment does not represent all execution modes consistent with the present invention.On the contrary, they only with as in appended claims describe in detail, the example of apparatus and method that aspects more of the present invention are consistent.
Fig. 1 is the flow chart of a kind of method for processing business that the embodiment of the present invention provides, and as shown in Figure 1, comprises the following steps.
In a step 101, in business procession, store the contextual information of the worker thread sending far call request, and identify for this contextual information distributes contextual information, and this contextual information and this contextual information mark are bound.
In a step 102, this far call request and this contextual information mark are sent to given server, make this far call request of this given server process and return the result of this far call request, this result carries this contextual information mark.
In step 103, receive this result, and according to the binding relationship that the contextual information that this result is carried identifies and prestores, obtain and identify with this contextual information the contextual information bound.
At step 104, identify according to this contextual information the contextual information and this result bound, carry out this business procession.
The method that the embodiment of the present invention provides, by preserving the contextual information of thread, and identify for this contextual information distributes contextual information, and this contextual information is bound, when sending far call request to given server, send this contextual information mark simultaneously, when given server returns the result of this far call request, return this contextual information mark simultaneously, make server can obtain contextual information according to this contextual information mark and binding relationship, to proceed Business Processing, said method can avoid being in wait state at far call request processing procedure thread cannot be recovered utilization, and then the problem of thread block can be avoided.
In the first possibility implementation of the present invention, before this storage sends the contextual information of the worker thread of far call request, the method also comprises:
When capturing far call request, registered callbacks function, this call back function is used for when getting the result of this far call request, carries out Business Processing according to this result;
After storing the contextual information of the worker thread sending far call request, the method also comprises:
This far call request is stored to designated storage area;
Before this far call request and this contextual information mark are sent to given server, the method also comprises:
This far call request is read from this designated storage area.
In the second possibility implementation of the present invention, after this far call request is stored to designated storage area, the method also comprises:
Discharge the worker thread of this transmission far call request, the worker thread after release is put back to thread pool.
In the third possibility implementation of the present invention, this far call request and this contextual information mark are sent to given server and comprise: by transmission control protocol TCP passage, this far call request and this contextual information mark are sent to given server.
In the 4th kind of possibility implementation of the present invention, this business procession is asynchronous process process.
Above-mentioned all alternatives, can adopt and combine arbitrarily formation optional embodiment of the present invention, this is no longer going to repeat them.
Fig. 2 is the flow chart of a kind of method for processing business that the embodiment of the present invention provides.The executive agent of this embodiment can be server, and with reference to Fig. 2, this embodiment specifically comprises:
In step 201, in business procession, when capturing far call request, registered callbacks function, this call back function is used for when getting the result of this far call request, carries out Business Processing according to this result.
In the catenet application of distributed structure/architecture, due to the distributivity feature of application architecture, when carrying out Business Processing, unavoidably there will be far call.Such as, in this distributed structure/architecture, comprise a current server carrying out Business Processing, in the processing procedure of this server, there will be some far call demands, therefore, this server can send far call request to other servers (only referring to given server in inventive embodiments) in distributed structure/architecture.At present, far call in business procession is a synchronous processing procedure normally, that is to say, after far call request is sent to given server by worker thread, until receive the result of this far call request, this worker thread is in wait state always.But when server needs traffic carrying capacity to be processed comparatively large, or when far call request is more, waiting worker thread cannot be recovered utilization, cause disposal ability during the high concurrent far call request of the method for processing business of synchronous mode reply lower.In order to solve the problem, the invention provides a kind of method for processing business based on the request of asynchronous process far call, that is to say, this business procession is asynchronous process process.
In embodiments of the present invention, before this far call request of transmission, first registered callbacks function, this call back function is used for the result of this far call request of process further, concrete grammar can be: by preserving the function pointer of this call back function, waiting when receiving the result of far call request, call this call back function by this function pointer.Certainly, also can be registered by additive method, the embodiment of the present invention is not construed as limiting this.
In step 202., store the contextual information of the worker thread sending far call request, and identify for this contextual information distributes contextual information, and this contextual information and this contextual information mark are bound.
In order to avoid waiting worker thread cannot recycle, in embodiments of the present invention, before the request of transmission far call, the contextual information of the worker thread sending far call request is carried out corresponding stored, and be that this contextual information distributes contextual information mark, and this contextual information and this contextual information are identified bind.Wherein, this contextual information at least comprises: the intermediate variable produced in business procession, and also can comprise the storage space information of these intermediate variables, the precedence information etc. of this worker thread, the embodiment of the present invention is not construed as limiting this.
It should be noted that, the number information that this contextual information mark can be stochastic generation, be made up of symbol or numeral, also can be the other forms of information produced by other means, the embodiment of the present invention be not construed as limiting this.After this contextual information and this contextual information identified binding, search for the ease of follow-up, binding relationship can be stored, also contextual information mark can be carried out corresponding stored with contextual information, the embodiment of the present invention is not construed as limiting this.
After storing the contextual information of the worker thread sending far call request, this far call request is stored to designated storage area; In embodiments of the present invention, this designated storage area is TCP (TransmissionControlProtocol, transmission control protocol) buffering area.After this far call request is stored to designated storage area, discharge the worker thread of this transmission far call request, worker thread after release is put back to thread pool, avoid worker thread to be in wait state before receiving this far call request result always, and then the quantity of available thread in thread pool can be improved, correspondingly, when far call request is more, service process performance can be improved.In particular, when the far call request processing time is longer, the present invention can shorten the stand-by period of worker thread greatly, and then obviously improves traffic handing capacity.Wherein, thread pool is at least for the worker thread to be called such as storing.
The contextual information of the above-mentioned worker thread to sending far call request stores, and can guarantee, after the result receiving far call request, to proceed the Business Processing do not completed according to the contextual information stored.
In step 203, this far call request and this contextual information mark are sent to given server, make this far call request of this given server process and return the result of this far call request, this result carries this contextual information mark.
This far call request is read from this designated storage area, and by transmission control protocol TCP passage, this far call request and this contextual information mark are sent to given server, this given server is used for according to this far call request, call the corresponding program in this given server or this far call request of corresponding function resume module, and return the result of this far call request.Wherein, this far call request and this contextual information mark are transmitted by TCP channel all in binary form; This given server is for different requests, and adopt diverse ways to process, the concrete processing method of the present invention to this given server does not repeat.
It should be noted that, this result carries this contextual information mark, after receiving this result, can identify according to this contextual information to make server, obtains corresponding contextual information, to have continued current business procession.
In step 204, receive this result, and according to the binding relationship that the contextual information that this result is carried identifies and prestores, obtain and identify with this contextual information the contextual information bound.
By the result that TCP channel reception given server returns, with step 203, send the method for far call request in like manner to given server, this result is also transmitted in the form of binary data.The contextual information mark of carrying according to this result and the binding relationship prestored, obtain contextual information.
In step 205, identify according to this contextual information the contextual information and this result bound, carry out this business procession.
The contextual information that the result received according to step 204 and step 202 are preserved, the worker thread in invokes thread pond and registered call back function, proceed the processing procedure of this business.
Above-mentioned method for processing business can be applied in arbitraryly to be had in the business procession of far call process, and concrete processing procedure is described further for Fig. 3.
User side sends user's request by user end to server mounted in terminal, at server in the process of this user of process request, when capturing far call request, first registered callbacks function, and preserve the contextual information of work at present thread, for this contextual information distributes contextual information mark, and bind, after this far call request is stored to designated storage area, this current worker thread is released into thread pool, calls for during other business of this server process; After server process to be specified is complete, this server receives the result that this given server returns, this result carries context id information, contextual information is obtained according to this context id information, start thread according to this result and contextual information and carry out readjustment process, proceed business procession, to obtain the result of user's request; After user to be obtained asks result, result is asked to be back to user terminal this user.
The method that the embodiment of the present invention provides, by preserving the contextual information of thread, and identify for this contextual information distributes contextual information, and this contextual information is bound, when sending far call request to given server, send this contextual information mark simultaneously, when given server returns the result of this far call request, return this contextual information mark simultaneously, make server can obtain contextual information according to this contextual information mark and binding relationship, to proceed Business Processing, said method can avoid being in wait state at far call request processing procedure thread cannot be recovered utilization, and then the problem of thread block can be avoided.Further, by the thread preserving contextual information is put back to thread pool, the quantity of available thread in thread pool can be improved, correspondingly, when far call request is more, can service process performance be improved.
Fig. 4 is a kind of business processing device block diagram that the embodiment of the present invention provides.With reference to Fig. 4, this device comprises the first processing module 401, sending module 402, receiver module 403 and the second processing module 404.
First processing module 401, in business procession, stores the contextual information of the worker thread sending far call request, and identifies for this contextual information distributes contextual information, and this contextual information and this contextual information mark is bound;
Sending module 402, this contextual information mark for this far call request and this first processing module 401 being distributed for this contextual information is sent to given server, make this far call request of this given server process and return the result of this far call request, this result carries this contextual information mark;
Receiver module 403, for receiving this result, and according to the binding relationship that the contextual information that this result is carried identifies and prestores, obtains and identifies with this contextual information the contextual information bound;
Second processing module 404, for identifying according to this contextual information the contextual information and this result bound, carries out this business procession.
In the first possibility implementation provided by the invention, this first processing module 401 is also for when capturing far call request, registered callbacks function, this call back function is used for when getting the result of this far call request, carries out Business Processing according to this result;
This device also comprises:
Memory module, for being stored to designated storage area by this far call request;
Read module, for reading this far call request from this designated storage area.
In the second possibility implementation provided by the invention, thread release module, for discharging the worker thread of this transmission far call request, puts back to thread pool by the worker thread after release.
Provided by the invention the third may in implementation, this sending module 402 for: by transmission control protocol TCP passage, this far call request and this contextual information mark are sent to given server.
In the 4th kind of possibility implementation provided by the invention, this business procession is asynchronous process process.
About the device in above-described embodiment, wherein the concrete mode of modules executable operations has been described in detail in about the embodiment of the method, will not elaborate explanation herein.
Fig. 5 is the block diagram of a kind of business processing device 500 that the embodiment of the present invention provides.Such as, device 500 may be provided in a server.With reference to Fig. 5, device 500 comprises processing components 522, and it comprises one or more processor further, and the memory resource representated by memory 532, can such as, by the instruction of the execution of processing unit 522, application program for storing.The application program stored in memory 532 can comprise each module corresponding to one group of instruction one or more.In addition, processing components 522 is configured to perform instruction, to perform above-mentioned method for processing business.
Device 500 can also comprise the power management that a power supply module 526 is configured to final controlling element 500, and a wired or wireless network interface 550 is configured to device 500 to be connected to network, and input and output (I/O) interface 558.Device 500 can operate the operating system based on being stored in memory 532, such as WindowsServer
tM, MacOSX
tM, Unix
tM, Linux
tM, FreeBSD
tMor it is similar.
One of ordinary skill in the art will appreciate that all or part of step realizing above-described embodiment can have been come by hardware, the hardware that also can carry out instruction relevant by program completes, described program can be stored in a kind of computer-readable recording medium, the above-mentioned storage medium mentioned can be read-only memory, disk or CD etc.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.