Specific embodiment
To keep the purposes, technical schemes and advantages of this specification clearer, it is embodied below in conjunction with this specification
This specification technical solution is clearly and completely described in example and corresponding attached drawing.Obviously, described embodiment is only this
Specification a part of the embodiment, instead of all the embodiments.The embodiment of base in this manual, ordinary skill people
Member's every other embodiment obtained without making creative work, belongs to the range of this specification protection.
This specification embodiment provides a kind of distributed transaction processing method and terminal device, to solve to divide in the prior art
The execution link of cloth issued transaction is more, the longer problem of total time-consuming.This specification embodiment provides a kind of distributed transaction
Processing method, the executing subject of this method can be, but not limited to the task manager of distributed transaction or can be configured as holding
The device or system of this method that row this specification embodiment provides.
For ease of description, hereafter executing subject in this way is to be able to carry out for the task manager of this method, it is right
The embodiment of this method is introduced.It is appreciated that it is that one kind is exemplary that the executing subject of this method, which is task manager,
Explanation, be not construed as the restriction to this method.
Fig. 3 is the flow chart for the distributed transaction processing method that this specification embodiment provides, and the method for Fig. 3 can be by thing
Business manager executes, as shown in figure 3, this method may include:
Step 310, the request operation in response to distributed transaction, send the distribution to multiple resource managers respectively
The preparation operation requests of the subtransaction of affairs.
Implementing result of the preparation operation requests for the resource of the corresponding subtransaction of request confirmation.
Step 320, based on the multiple resource manager to the preparation operation requests of the subtransaction of the distributed transaction
Response results, the corresponding transaction operation of the response results is executed to the distributed transaction by asynchronous system.
The preparation operation of the subtransaction of distributed transaction is asked it will be appreciated that task manager obtains multiple resource managers
After the response results asked, the corresponding transaction operation of response results is executed to distributed transaction by asynchronous system.
In other words, task manager obtains multiple resource managers and asks to the preparation operation of the subtransaction of distributed transaction
After the response results asked, the processing of distributed transaction is completed in task manager.
The response results can be to prepare successfully or prepare failure;Alternatively, the response results can be to run succeeded or hold
Row failure.
The corresponding transaction operation of the response results is executed to the distributed transaction by asynchronous system, specific implementation can
With are as follows:
Task manager is by multiple resource managers to the response knot of the preparation operation requests of the subtransaction of distributed transaction
Fruit is reported to other equipment, and e.g., server is grasped as a result, executing the corresponding affairs of the response results according to response by other equipment
Make;Alternatively,
Task manager is by multiple resource managers to the response knot of the preparation operation requests of the subtransaction of distributed transaction
Fruit distributes to multiple synchronizing threads in thread pool, is corresponded to according to response as a result, executing the response results by multiple synchronizing threads
Transaction operation.
This specification embodiment is based on multiple resource managers to the preparation operation requests of the subtransaction of distributed transaction
Response results execute the corresponding transaction operation of response results to distributed transaction by asynchronous system, so that response results are corresponding
Transaction operation by asynchronous system execute, reduce the execution link of distributing real time system, shorten distributed transaction
Execute loss.
Optionally, as one embodiment, the distributed transaction processing method that this specification embodiment provides can also be wrapped
It includes:
It receives the affairs that client is sent and starts request, and request corresponding distributed transaction to divide affairs starting
Multiple subtransactions, be assigned to the processing that the multiple resource manager is prepared operation.
For example, it is assumed that " account A transfers accounts to account B " is used as a distributed transaction, then need in three resource managements
The enterprising row write operation (that is, the distributed transaction is segmented into three subtransactions) of device, is respectively as follows:
Operation 1 to account A deducts predetermined dollar value on resource manager 1;
Operation 2 gives account B to add the corresponding amount of money on resource manager 2;
Operation 3 transfer accounts on resource manager 3 summarizing.
Wherein, if it is all to prepare successfully that three resource managers, which are prepared the response results after operation processing, it is determined that
Submission operation is carried out to the distributed transaction;If three resource managers are prepared in the response results after operation processing at least
It is to prepare failure there are a response results, it is determined that rolling back action is carried out to the distributed transaction.
In practical applications, illustratively, the implementation procedure that the method for this specification is described in detail in above-mentioned example is continued to use:
User initiates the operation of " account A transfers accounts to account B " in client, and the operation carried out according to user is to transaction management
Device registers distributed transaction;Task manager can distribute Transaction Identifier ID for the distributed transaction." account A transfers accounts to account B "
It needs in the enterprising row write operation of three resource managers, that is to say, that the distributed transaction is segmented into three subtransactions:
Operation 1 to account A deducts predetermined dollar value on resource manager 1;
Operation 2 gives account B to add the corresponding amount of money on resource manager 2;
Operation 3 transfer accounts on resource manager 3 summarizing.
Wherein, if it is all to prepare successfully that three resource managers, which are prepared the response results after operation processing, it is determined that
Submission operation is carried out to the distributed transaction;If three resource managers are prepared in the response results after operation processing at least
It is to prepare failure there are a response results, it is determined that rolling back action is carried out to the distributed transaction.
After the completion of each subtransaction processing, response results of the task manager based on all subtransactions pass through asynchronous system
The corresponding transaction operation of response results is executed to the distributed transaction.
Such as, after task manager reports the response results of all subtransactions to standby database, server end as coordinator,
The response results for each subtransaction in database are inquired, and are determined according to the response results of each subtransaction inquired
Initiate the submission or rollback of the distributed transaction;Alternatively,
The corresponding subtransaction of multiple response results is distributed to thread pool according to default allocation rule by task manager
In multiple synchronizing threads, by multiple synchronizing threads based on response results determine initiate the distributed transaction submission or rollback.
Optionally, as one embodiment, step 120 specifically be can be achieved are as follows:
The corresponding subtransaction of multiple response results is distributed to according to default allocation rule more in thread pool
A synchronizing thread is pre-configured with multiple synchronizing threads in the thread pool;
Multiple synchronizing threads in the thread pool are used to execute the sound to the distributed transaction by asynchronous system
Answer the corresponding transaction operation of result.
In this application, it needs to pre-establish thread pool, the synchronizing thread in thread pool can be in the present embodiment are as follows: need
The thread for calling run method to execute.
For example, being pre-configured with 10 synchronizing threads in thread pool, this 10 thread synchronizations are required using run method
It executes, and this 10 synchronizing threads for using run method to execute can carry out in main thread when being executed, so that together
The end time of step thread execution task can be perceived by main thread.
Wherein, thread pool can directly or indirectly extend from JDK (Java Development Kit, Java language it is soft
Part development kit) provide ThreadPoolExecutor.Thread pool in the present embodiment
(DoImmediatelyThreadPoolTaskExecutor) different from thread pool in the prior art, the line in the present embodiment
The synchronizing thread of Cheng Chi is all that run method is called to execute, so that synchronizing thread can synchronize execution in the main thread of calling.
Wherein, the corresponding subtransaction of multiple response results is distributed in thread pool according to default allocation rule
Multiple synchronizing threads, be pre-configured with multiple synchronizing threads in the thread pool, specific implementation may include:
Step A1: task queue is established for the thread pool.
Firstly, establishing a task queue for the thread pool created, which can deposit according to sequencing
Put the distributing to the synchronizing thread in thread pool of the task.
Step A2: multiple subtransactions are added separately to described appoint according to each user for triggering the multiple subtransaction
It is engaged in queue.
In the present embodiment, multiple subtransactions can be added separately to according to the difference of the user of triggering subtransaction
In task queue.
For example, mending account business for the buffering in practical application, there are four users to trigger 7 tasks that buffering mends account.
It is specific as shown in table 1:
Table 1
User task |
id |
A |
1 |
A |
2 |
A |
3 |
B |
4 |
B |
5 |
C |
6 |
D |
7 |
Three subtransactions of user A can be first added so in task queue, then add two subtransactions of user B, then
Successively add the task of user C and user D.
Step A3: the multiple synchronizing threads subtransaction in the task queue being respectively allocated in thread pool, wherein
Each user corresponds to a synchronizing thread.
Then the subtransaction in task queue is respectively allocated to multiple synchronizing threads in thread pool again, for example, each
The subtransaction correspondence of user distributes to a synchronizing thread.So, shown in reference table 1, three subtransactions of user A can be distributed
To first synchronizing thread in thread pool, and two subtransactions of user B can distribute to second synchronization in thread pool
Thread, and so on.
Certainly, in practical applications, it is not limited only to distribute thread for task by dimension of user, it can also be with sub- thing
Business is dimension, for each subtransaction one synchronizing thread of corresponding distribution, can also use other methods of salary distribution certainly.
As shown in figure 4, this specification embodiment, returns resource managers all in a stage in two-stage task manager
The corresponding subtransaction of multiple response results returned distributes to multiple synchronizing threads in thread pool according to default allocation rule,
The corresponding affairs of the response results are executed to distributed transaction by asynchronous system by multiple synchronizing threads in thread pool to grasp
Make, so that task manager becomes the summation of a+b+c+g to the reduction of entire distributed transaction execution link, total time-consuming, effectively contracts
Short distributed transaction executes loss.
Optionally, as one embodiment, step 120 specifically be can be achieved are as follows:
The corresponding relationship of the request of transaction operation corresponding to the response results and response results and response results is stored
In standby database, so that other equipment are based on the response results inquired in the standby database, asynchronous execution institute
State the corresponding transaction operation of response results.
The standby database can be the database of other equipment, or relative to the independent data of other equipment
Library, this specification embodiment are not specifically limited.
Illustratively, after task manager reports the response results of all subtransactions to standby database, server end conduct
Coordinator inquires the response results for each subtransaction in database, and according to the response of each subtransaction inquired
As a result the submission or rollback for determining the initiation distributed transaction, specifically, if all subtransactions of the distributed transaction
Response results be all to prepare successfully, it is determined that the distributed transaction is submitted, if in all subtransactions at least
It is the subtransaction for preparing failure there are a response results, it is determined that rollback is carried out to the distributed transaction.Specifically, clothes
Business device determined to distributed transaction submit or rollback after, send submiting command or rollback order to each subtransaction, with
Initiate the submission or rollback of global transaction.Therefore, the submission distributed transaction that can be sent according to the server received
Order, execute the submission of the distributed transaction;Or the distribution thing according to the rollback that the server received is sent
The order of business executes the rollback of the distributed transaction.In other words, if divided described in the submission that the server received is sent
The order of cloth affairs then executes the submission of the distributed transaction;If divided described in the rollback that the server received is sent
The order of cloth affairs then executes the rollback of the distributed transaction.
This specification embodiment, by asking response results and response results with transaction operation corresponding to response results
The corresponding relationship asked is stored in standby database, by other equipment based on the response knot inquired in the standby database
Fruit executes the corresponding transaction operation of response results, realizes the corresponding transaction operation of response results and executed by asynchronous system
Purpose, reduce the execution link of distributing real time system, shorten distributed transaction executes loss.
More than, the distributed transaction processing method of this specification embodiment is described in detail in conjunction with Fig. 3 to Fig. 4, in the following, knot
Fig. 5 is closed, the task manager of this specification embodiment is described in detail.
Fig. 5 shows the structural schematic diagram of the task manager of this specification embodiment offer, as shown in figure 5, the affairs
Manager 500 may include:
Sending module 501 sends institute to multiple resource managers respectively for the request operation in response to distributed transaction
The preparation operation requests of the subtransaction of distributed transaction are stated, the operation requests that prepare are for the corresponding subtransaction of request confirmation
The implementing result of resource;
Execution module 503, for the preparation based on the multiple resource manager to the subtransaction of the distributed transaction
The response results of operation requests execute the corresponding affairs of the response results to the distributed transaction by asynchronous system and grasp
Make.
In one embodiment, the execution module 503 may include:
Allocation unit, for distributing to the corresponding subtransaction of multiple response results according to default allocation rule
Multiple synchronizing threads in thread pool are pre-configured with multiple synchronizing threads in the thread pool;
Execution unit is used for through asynchronous system for multiple synchronizing threads in the thread pool to the distributed thing
Business executes the corresponding transaction operation of the response results.
In one embodiment, the allocation unit may include:
Subelement is established, for establishing task queue for the thread pool;
Subelement is added, for adding multiple subtransactions respectively according to each user for triggering the multiple subtransaction
To in the task queue;
Distribute subelement, multiple line synchros for being respectively allocated to the subtransaction in the task queue in thread pool
Journey, wherein the corresponding synchronizing thread of each user.
In one embodiment, the execution module 503 may include:
Storage unit, for requesting transaction operation corresponding to the response results and response results and response results
Corresponding relationship be stored in standby database, so that other equipment are based on the response knot inquired in the standby database
Fruit, the corresponding transaction operation of response results described in asynchronous execution.
In one embodiment, the task manager can also include:
Distribution module 505 is received, for receiving the affairs starting request of client transmission, and the affairs is started and are requested
Multiple subtransactions that corresponding distributed transaction divides, are assigned to the processing that the multiple resource manager is prepared operation.
This specification embodiment is based on multiple resource managers to the preparation operation requests of the subtransaction of distributed transaction
Response results execute the corresponding transaction operation of response results to distributed transaction by asynchronous system, so that response results are corresponding
Transaction operation by asynchronous system execute, reduce the execution link of distributing real time system, shorten distributed transaction
Execute loss.
More than, the distributed transaction processing method of this specification embodiment is described in detail in conjunction with Fig. 3 to Fig. 4, in the following, knot
Fig. 6 is closed, the distributing real time system system of this specification embodiment is described in detail.
Fig. 6 shows the structural schematic diagram of the distributing real time system system of this specification embodiment offer, such as Fig. 6 institute
Show, which may include:
Task manager 601 is operated in response to the request of distributed transaction, respectively to described in the transmission of multiple resource managers
The preparation operation requests of the subtransaction of distributed transaction, the money for preparing operation requests and being used for the corresponding subtransaction of request confirmation
The implementing result in source;
Task manager 601 distributes to the corresponding subtransaction of multiple response results according to default allocation rule
Multiple synchronizing threads 603 in thread pool are pre-configured with multiple synchronizing threads in the thread pool;
Multiple synchronizing threads 603 in the thread pool execute the response to the distributed transaction by asynchronous system
As a result corresponding transaction operation.
This specification embodiment is based on multiple resource managers to the preparation operation requests of the subtransaction of distributed transaction
Response results execute the corresponding transaction operation of response results to distributed transaction by asynchronous system, so that response results are corresponding
Transaction operation by asynchronous system execute, reduce the execution link of distributing real time system, shorten distributed transaction
Execute loss.
More than, the distributed transaction processing method of this specification embodiment is described in detail in conjunction with Fig. 3 and Fig. 4, in the following, knot
Fig. 7 is closed, the distributing real time system system of this specification embodiment is described in detail.
Fig. 7 shows the structural schematic diagram of the distributing real time system system of this specification embodiment offer, such as Fig. 7 institute
Show, which may include:
Task manager 701 is operated in response to the request of distributed transaction, respectively to described in the transmission of multiple resource managers
The preparation operation requests of the subtransaction of distributed transaction, the money for preparing operation requests and being used for the corresponding subtransaction of request confirmation
The implementing result in source;
Task manager 701 requests transaction operation corresponding to the response results and response results and response results
Corresponding relationship be stored in standby database 703;
Other equipment 705 respond knot based on the response results inquired in the standby database described in asynchronous execution
The corresponding transaction operation of fruit.
This specification embodiment is based on multiple resource managers to the preparation operation requests of the subtransaction of distributed transaction
Response results execute the corresponding transaction operation of response results to distributed transaction by asynchronous system, so that response results are corresponding
Transaction operation by asynchronous system execute, reduce the execution link of distributing real time system, shorten distributed transaction
Execute loss.
Fig. 8 is the structural schematic diagram for the terminal device that one embodiment of this specification provides.Referring to FIG. 8, in hardware
Level, the terminal device include processor, optionally further comprising internal bus, network interface, memory.Wherein, memory can
It can include memory, such as high-speed random access memory (Random-AccessMemory, RAM), it is also possible to further include non-volatile
Property memory (non-volatile memory), for example, at least 1 magnetic disk storage etc..Certainly, which is also possible to wrap
Include hardware required for other business.
Processor, network interface and memory can be connected with each other by internal bus, which can be ISA
(Industry Standard Architecture, industry standard architecture) bus, PCI (Peripheral
Component Interconnect, Peripheral Component Interconnect standard) bus or EISA (Extended Industry Standard
Architecture, expanding the industrial standard structure) bus etc..The bus can be divided into address bus, data/address bus, control always
Line etc..Only to be indicated with a four-headed arrow in Fig. 8, it is not intended that an only bus or a type of convenient for indicating
Bus.
Memory, for storing program.Specifically, program may include program code, and said program code includes calculating
Machine operational order.Memory may include memory and nonvolatile memory, and provide instruction and data to processor.
Processor is from the then operation into memory of corresponding computer program is read in nonvolatile memory, in logical layer
The associated apparatus of resource increment object and resource object is formed on face.Processor executes the program that memory is stored, and specific
For performing the following operations:
In response to the request operation of distributed transaction, the son of the distributed transaction is sent to multiple resource managers respectively
The preparation operation requests of affairs, the implementing result for preparing operation requests and being used for the resource of the corresponding subtransaction of request confirmation;
Based on the multiple resource manager to the response knot of the preparation operation requests of the subtransaction of the distributed transaction
Fruit executes the corresponding transaction operation of the response results to the distributed transaction by asynchronous system.
This specification embodiment is based on multiple resource managers to the preparation operation requests of the subtransaction of distributed transaction
Response results execute the corresponding transaction operation of response results to distributed transaction by asynchronous system, so that response results are corresponding
Transaction operation by asynchronous system execute, reduce the execution link of distributing real time system, shorten distributed transaction
Execute loss.
Distributed transaction processing method disclosed in the above-mentioned embodiment illustrated in fig. 3 such as this specification can be applied to processor
In, or realized by processor.Processor may be a kind of IC chip, the processing capacity with signal.It was realizing
Each step of Cheng Zhong, the above method can be complete by the integrated logic circuit of the hardware in processor or the instruction of software form
At.Above-mentioned processor can be general processor, including central processing unit (Central Processing Unit, CPU),
Network processing unit (Network Processor, NP) etc.;It can also be digital signal processor (Digital Signal
Processor, DSP), it is specific integrated circuit (Application Specific Integrated Circuit, ASIC), existing
Field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device are divided
Vertical door or transistor logic, discrete hardware components.It may be implemented or execute this specification one or more embodiment
In disclosed each method, step and logic diagram.General processor can be microprocessor or the processor is also possible to
Any conventional processor etc..The step of method in conjunction with disclosed in this specification one or more embodiment, can directly embody
Execute completion for hardware decoding processor, or in decoding processor hardware and software module combination execute completion.Software
Module can be located at random access memory, flash memory, read-only memory, programmable read only memory or electrically erasable programmable storage
In the storage medium of this fields such as device, register maturation.The storage medium is located at memory, and processor reads the letter in memory
Breath, in conjunction with the step of its hardware completion above method.
The terminal device can also carry out the distributing real time system side of Fig. 1 performed by the distributing real time system device of Fig. 3
Method, details are not described herein for this specification.
Certainly, other than software realization mode, other implementations are not precluded in the terminal device of this specification, such as
Logical device or the mode of software and hardware combining etc., that is to say, that the executing subject of following process flow is not limited to each
Logic unit is also possible to hardware or logical device.
This specification embodiment also provides a kind of computer readable storage medium, is stored on computer readable storage medium
Computer program, the computer program realize each process of above-mentioned each embodiment of the method when being executed by processor, and can reach
To identical technical effect, to avoid repeating, which is not described herein again.Wherein, the computer readable storage medium, it is such as read-only
Memory (Read-Only Memory, abbreviation ROM), random access memory (Random Access Memory, abbreviation
RAM), magnetic or disk etc..
It should be understood by those skilled in the art that, the embodiment of this specification can provide as method, system or computer journey
Sequence product.Therefore, in terms of this specification can be used complete hardware embodiment, complete software embodiment or combine software and hardware
Embodiment form.Moreover, it wherein includes computer usable program code that this specification, which can be used in one or more,
The computer implemented in computer-usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.)
The form of program product.
This specification is referring to the method, equipment (system) and computer program product according to this specification embodiment
Flowchart and/or the block diagram describes.It should be understood that can be realized by computer program instructions every in flowchart and/or the block diagram
The combination of process and/or box in one process and/or box and flowchart and/or the block diagram.It can provide these computers
Processor of the program instruction to general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices
To generate a machine, so that generating use by the instruction that computer or the processor of other programmable data processing devices execute
It is in realize the function of specifying in one or more flows of the flowchart and/or one or more blocks of the block diagram
System.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of system, the instruction system realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It is above-mentioned that specification specific embodiment is described.Other embodiments are within the scope of the appended claims.
In some cases, the movement recorded in detail in the claims or step can be executed according to the sequence being different from embodiment
And desired result still may be implemented.In addition, process depicted in the drawing not necessarily require the particular order shown or
Person's consecutive order is just able to achieve desired result.In some embodiments, multitasking and parallel processing are also possible
Or it may be advantageous.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including element
There is also other identical elements in process, method, commodity or equipment.
The above is only the embodiments of this specification, are not limited to this specification.For those skilled in the art
For, this specification can have various modifications and variations.All any modifications made within the spirit and principle of this specification,
Equivalent replacement, improvement etc., should be included within the scope of the claims of this specification.