Task conversion method and device

By using blocking objects and local cache collections in the server components, combined with the Redis channel mode, the accurate correspondence and association between asynchronous tasks and servers is achieved, solving the problem of asynchronous task positioning errors in the service cluster deployment environment, and simplifying operation and maintenance, realizing multi-machine deployment.

CN120066690APending Publication Date: 2025-05-30BEIJING JINGDONG YUANSHENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311606415.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-28
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

In the service cluster deployment environment, asynchronous tasks cannot accurately locate services, resulting in task execution errors. The existing solution uses message queue to obtain asynchronous task execution results, increasing the difficulty of operation and maintenance.

Method used

By introducing blocking objects and local cache collections into the server components, using globally unique asynchronous task identifiers to create blocking objects, and adding records to the local cache collection, the accurate correspondence between asynchronous tasks and the server is achieved. Use Redis as an external middleware to obtain task execution result messages through channel mode to realize a set of code deployment multiple machines.

Benefits of technology

It realizes the accurate correspondence and correlation between asynchronous tasks and servers, avoids errors in the execution process of asynchronous tasks, simplifies operation and maintenance, and realizes a set of code deployment capabilities for multiple machines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066690A_ABST
    Figure CN120066690A_ABST
Patent Text Reader

Abstract

The invention discloses a task conversion method and device, and relates to the technical field of computers. A specific embodiment of the method comprises the following steps: in response to receiving a globally unique asynchronous task identifier which is sent by a server and indicates an asynchronous task, creating a blocking object by utilizing the asynchronous task identifier; adding a record containing an asynchronous task identifier in a local cache set of the server, and executing thread blocking on the server based on a blocking object; under the condition that a task execution result message which is sent by the asynchronous task execution end and contains the target asynchronous task identifier is obtained from preset external middleware, whether the target asynchronous task identifier exists in a local cache set or not is judged; and if yes, returning a task execution result in the task execution result message to the server, and performing thread awakening on the server to convert the asynchronous task into the synchronous task. According to the embodiment, the asynchronous task can accurately correspond to the server in the asynchronous task conversion process of the service cluster deployment environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a task conversion method and apparatus. Background Art

[0002] There are a large number of asynchronous tasks in a computer system. In some specific scenarios (such as process orchestration), it is necessary to obtain the execution result of an asynchronous task before performing the next step, that is, it is necessary to convert an asynchronous task into a synchronous task. In existing solutions, most of them are implemented based on a single-machine system. However, in a service cluster deployment environment, it is impossible to determine which service called an asynchronous task itself, so the service cannot be accurately located, which easily leads to incorrect task execution. In addition, existing solutions generally obtain the execution result of an asynchronous task through a message queue. When the message queue implements the above function, different groups need to be set for each service. Therefore, it is impossible to deploy a set of code on multiple machines, increasing the operation and maintenance difficulty. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a task conversion method and apparatus, which can accurately correspond an asynchronous task to a server during the conversion of an asynchronous task in a service cluster deployment environment.

[0004] To achieve the above object, according to one aspect of the present invention, a task conversion method is provided.

[0005] The task conversion method of the embodiments of the present invention is executed by a component pre-introduced into a server; the method includes: in response to receiving a globally unique asynchronous task identifier indicating an asynchronous task sent by the server, creating a blocking object by using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; adding a record containing the asynchronous task identifier to a local cache set of the server, and blocking an execution thread of the server based on the blocking object; in the case of obtaining a task execution result message containing a target asynchronous task identifier sent by the preset external middleware from the asynchronous task execution end, determining whether the target asynchronous task identifier exists in the local cache set; if it exists, returning the task execution result in the task execution result message to the server, and waking up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0006] Optionally, the method further includes: after creating the blocking object by using the asynchronous task identifier, determining the current time as the creation time of the blocking object, and storing the blocking object, the creation time of the blocking object, and the asynchronous task identifier corresponding to the blocking object as a record in the local cache set.

[0007] Optionally, the external middleware is implemented based on Redis; and, the method further includes: subscribing in advance to a specific channel of the external middleware, and obtaining the task execution result message from the specific channel; wherein, the asynchronous task execution end acts as a producer of the external middleware to send a message to the specific channel.

[0008] Optionally, the method further includes: periodically querying the local cache set, and in the case of determining that there is a blocked object in the local cache set whose execution duration is greater than a preset duration threshold, determining the blocked object with an execution duration greater than the preset duration threshold as a timeout object; wherein, the execution duration of any blocked object is the difference between the current time and the creation time of the blocked object; returning the timeout execution result of the asynchronous task identifier corresponding to the timeout object to the server, and waking up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0009] Optionally, the method further includes: after returning the task execution result or the timeout execution result corresponding to any asynchronous task identifier to the server, deleting the record indicated by the asynchronous task identifier in the local cache set.

[0010] Optionally, the task execution result includes: a task execution status with a value of success or failure; in the case where the task execution status is success, the task execution result further includes: execution success data; in the case where the task execution status is failure, the task execution result further includes: a reason for execution failure.

[0011] To achieve the above object, according to another aspect of the present invention, there is provided a task conversion device.

[0012] The task conversion device of the embodiment of the present invention is provided in a component that is pre-introduced into the server; the device includes: an object creation unit, configured to: in response to receiving a globally unique asynchronous task identifier indicating an asynchronous task sent by the server, create a blocked object using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; a thread blocking unit, configured to add a record containing the asynchronous task identifier to the local cache set of the server, and block the execution thread of the server based on the blocked object; a thread wake-up unit, configured to, in the case of obtaining a task execution result message containing a target asynchronous task identifier sent by the asynchronous task execution end from a preset external middleware, determine whether the target asynchronous task identifier exists in the local cache set; if it exists, return the task execution result in the task execution result message to the server, and wake up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0013] Optionally, the external middleware is implemented based on Redis; and, the thread wake-up unit is further configured to: subscribe to a specific channel of the external middleware in advance, and obtain the task execution result message from the specific channel; wherein, the asynchronous task execution end acts as a producer of the external middleware to send a message to the specific channel.

[0014] To achieve the above object, according to another aspect of the present invention, there is provided an electronic device.

[0015] An electronic device of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the task conversion method provided by the present invention.

[0016] To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable storage medium.

[0017] A computer-readable storage medium of the present invention stores a computer program thereon, and when the program is executed by a processor, it implements the task conversion method provided by the present invention.

[0018] According to the technical solution of the present invention, the embodiments in the above invention have the following advantages or beneficial effects:

[0019] The conversion from an asynchronous task to a synchronous task is performed by a component of a server in a pre-introduced computer cluster. After the server encounters an asynchronous task that needs to be executed by an asynchronous task execution end during operation, it sends a globally unique asynchronous task identifier to the component. The component creates a blocking object using the asynchronous task identifier, adds a record containing the asynchronous task identifier to the local cache set of the server, and blocks the execution thread of the server based on the blocking object. Thereafter, the component waits for the task execution result. When a task execution result message sent by the asynchronous task execution end and containing the target asynchronous task identifier is obtained from a preset external middleware, if it is determined that the target asynchronous task identifier exists in the local cache set, it indicates that the corresponding asynchronous task is sent by the current server, and then the task execution result in the task execution result message is returned to the server, and the execution thread of the server is awakened, thereby converting the asynchronous task into a synchronous task. In this way, the accurate correspondence and association between the asynchronous task and the server during the asynchronous task conversion process in the service cluster deployment environment are achieved, and errors during the execution of the asynchronous task are avoided. In addition, using Redis to replace the traditional message queue module to establish the external middleware, from which the component obtains the message returned by the asynchronous task execution end, overcomes the defect that different groups need to be set for each service in the traditional message queue module, realizes multi-machine deployment with a set of code, and is convenient for later operation and maintenance.

[0020] The further effects of the above non-conventional alternative ways will be described below in conjunction with specific embodiments. Description of the Drawings

[0021] The drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention. Among them:

[0022] Figure 1 is a schematic diagram of the main steps of the task conversion method in an embodiment of the present invention;

[0023] Figure 2 is a schematic diagram of the overall process of the task conversion method in an embodiment of the present invention;

[0024] Figure 3 is a schematic diagram of the initialization process of the task conversion method in an embodiment of the present invention;

[0025] Figure 4 is a schematic diagram of the waiting callback process of the task conversion method in an embodiment of the present invention;

[0026] Figure 5 is a schematic diagram of the timeout callback process of the task conversion method in an embodiment of the present invention;

[0027] Figure 6 is a schematic diagram of the components of the task conversion device in an embodiment of the present invention;

[0028] Figure 7 is an exemplary system architecture diagram to which the embodiment of the present invention can be applied;

[0029] Figure 8 is a schematic diagram of the structure of an electronic device for implementing the task conversion method in an embodiment of the present invention. Detailed Embodiments

[0030] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description below omits the description of well-known functions and structures.

[0031] It should be noted that, without conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0032] Figure 1 is a schematic diagram of the main steps of the task conversion method according to an embodiment of the present invention.

[0033] Such as Figure 1As shown in the figure, the task conversion method according to the embodiment of the present invention can be executed by a component pre-introduced into the server, and can be specifically executed according to the following steps:

[0034] Step S101: In response to receiving a globally unique asynchronous task identifier indicating an asynchronous task sent by the server, create a blocking object by using the asynchronous task identifier.

[0035] It can be understood that a synchronous task refers to a task that needs to obtain the task execution result to continue the original logic, and an asynchronous task refers to a task that can execute the original logic without waiting for the execution result after handing the task to an external system for execution. In some specific scenarios, the execution mode of the asynchronous task may cause data errors. Therefore, it is necessary to convert the asynchronous task into a synchronous task, that is, modify the execution method of the asynchronous task to obtain the execution result returned by the external system and then execute the original logic. In this step, the server executes the business logic. When encountering an asynchronous task that needs to be executed by an external asynchronous task execution end, the server initiates the asynchronous task to the asynchronous task execution end and generates a globally unique (that is, unique within the entire computer cluster) asynchronous task identifier (that is, task ID) of the asynchronous task and sends it to the component. After receiving the asynchronous task identifier, the component creates a blocking object by using the asynchronous task identifier and executes the subsequent processing logic based on the blocking object. In practical applications, the blocking object can be a notification object NotifyBody in JUC (Java.Util.Concurrent, a concurrent programming technology).

[0036] Step S102: Add a record containing the asynchronous task identifier to the local cache set of the server, and block the execution thread of the server based on the blocking object.

[0037] Exemplarily, the above local cache set can be a thread-safe hash table ConcurrentHashMap. In this step, the component can add a record containing the asynchronous task identifier to the local cache set of the server to indicate which asynchronous tasks the server corresponds to, so as to realize the association and accurate correspondence between the server and its asynchronous tasks. In addition, the component can block the current business thread of the server based on the blocking object. Exemplarily, the NotifyBody.wait method can be executed to implement thread blocking, and the ConcurrentHashMap.put method can be used to insert a record into the local cache set.

[0038] In the embodiment of the present invention, after creating a blocking object by using the asynchronous task identifier, the component can determine the current time as the creation time of the blocking object, and store the blocking object, the creation time of the blocking object, and the asynchronous task identifier corresponding to the blocking object as a record in the local cache set. The creation time of the blocking object is used to calculate the execution duration of the blocking object subsequently and determine whether the blocking object times out.

[0039] Step S103: When a task execution result message containing a target asynchronous task identifier sent by an asynchronous task execution end is obtained from a preset external middleware, determine whether the target asynchronous task identifier exists in the local cache set; if it exists, return the task execution result in the task execution result message to the server, and wake up the server execution thread to convert the asynchronous task into a synchronous task.

[0040] Particularly, in the embodiment of the present invention, the asynchronous task execution end as a producer and the component as a consumer can perform message interaction based on an external middleware, and the above external middleware can be implemented based on the channel mode of Redis. Using Redis to replace the traditional message queue module to establish an external middleware from which the component obtains the message returned by the asynchronous task execution end can overcome the defect that different groups need to be set for each service in the traditional message queue module, realize multi-machine deployment of a set of codes, and facilitate later operation and maintenance. Specifically, the asynchronous task execution end, as the producer of the external middleware, sends a message to a specific channel of the external middleware, and the component subscribes to the above specific channel of the external middleware in advance and obtains the task execution result message from the specific channel.

[0041] When the component obtains a task execution result message containing a target asynchronous task identifier sent by the asynchronous task execution end from the preset external middleware, first determine whether the target asynchronous task identifier exists in the local cache set; if it exists, it means that the corresponding asynchronous task is sent from this server, then return the task execution result in the task execution result message to the server, and wake up the blocked server thread before, so as to convert the asynchronous task into a synchronous task; if it exists, it means that the corresponding asynchronous task is not sent from this server, then end the process. It can be understood that the component can use a separate thread (hereinafter referred to as the subscriber thread) to obtain the task execution result message. Exemplarily, the ConcurrentHashMap.get method can be used to query in the local cache set, and the NotifyBody.notify method can be used to wake up the thread. After returning the task execution result corresponding to any asynchronous task identifier to the server, the component can delete the record indicated by the asynchronous task identifier in the local cache set. In a specific application, the task execution result may include: a task execution status with a value of success or failure; in the case where the task execution status is success, the task execution result further includes the successfully executed data; in the case where the task execution status is failure, the task execution result further includes the reason for the execution failure, and the reason for the execution failure can help solve subsequent problems.

[0042] As a preferred solution, the component can use a separate thread (hereinafter referred to as the monitoring thread) to periodically query the local cache set. When it is determined that there is a blocked object in the local cache set whose execution duration is greater than a preset duration threshold, the blocked object with an execution duration greater than the preset duration threshold is determined as a timeout object. It can be understood that the execution duration of any blocked object is the difference between the current time and the creation time of the blocked object. After monitoring a timeout object, the component returns the timeout execution result of the asynchronous task identifier corresponding to the timeout object to the server and wakes up the server execution thread, thereby converting the asynchronous task into a synchronous task. Similarly, after the component returns the timeout execution result corresponding to any asynchronous task identifier to the server, it can delete the record indicated by the asynchronous task identifier in the local cache set.

[0043] Figure 2 is the overall flowchart of the task conversion method in the embodiment of the present invention. Refer to Figure 2 . After the server initiates scheduling, it executes the business logic. When an asynchronous task is encountered, it generates an asynchronous task identifier and passes it to the component, and then enters the waiting callback state. The component is embedded in the service code of the server. After receiving the asynchronous task identifier, it can create a blocked object and write the asynchronous task identifier, the blocked object, and the creation time of the blocked object into the local cache set, and then block the current business thread of the server. The subscriber thread of the component subscribes to messages from a specific channel of the external middleware, waits for messages, and parses them after receiving the messages to obtain the target asynchronous task identifier therein. Then, the subscriber thread queries the target asynchronous task identifier in the local cache set. If it is found, it wakes up the server execution thread and deletes the corresponding record. The monitoring thread of the component periodically queries whether there is a timeout object in the local cache set. If there is, it wakes up the execution thread and deletes the record after setting the timeout state of the object. If there is no timeout object, it continues to monitor and query periodically. The asynchronous task execution end executes the inherent logic to complete the asynchronous task and sends the task execution result message of the asynchronous task to a specific channel of the external middleware.

[0044] Figure 3 is the initialization (INIT) flowchart of the task conversion method in the embodiment of the present invention. Refer to Figure 3 . The initialization of the component will be completed when the service starts. There are mainly two steps. One is to start the subscriber thread to listen to a specific channel of the external middleware, and the other is to start the monitoring thread to provide a fallback for abnormal situations.

[0045] Figure 4 is the waiting callback (WAIT_CALL_BACK) flowchart of the task conversion method in the embodiment of the present invention. Refer to Figure 4。The waiting callback part is mainly divided into thread blocking suspension and thread wake-up. After the application side of the server initiates an asynchronous task, it passes the task ID (asynchronous task identifier) to the component. The component generates a blocking object using the task ID, puts the blocking object into the local cache set with the task ID as the key, and then blocks and waits for the callback. When the asynchronous task side finishes executing the task, it puts the execution result into a specific channel of the external middleware in a predefined format (such as task ID: execution status STATUS). At this time, all services listening to this specific channel will receive this message, and then look it up in the local cache combination according to the task ID. If there is such a key, the corresponding object is taken out, the execution status (success or failure) is set, and the thread is woken up. If there is no such key, it means that this task is not initiated by this service, and no operation is performed.

[0046] Figure 5 It is a schematic diagram of the timeout callback process of the task conversion method in an embodiment of the present invention. See Figure 5 。The monitoring thread will regularly scan all blocking objects within this service. When the duration (execution duration) of the existence of the blocking object exceeds the duration threshold set by the user, the callback timeout logic will be triggered, and then the blocking object will be woken up and the failure status of the timeout will be set.

[0047] In the technical solution of the embodiment of the present invention, a component for converting asynchronous tasks into synchronous tasks under distributed deployment is implemented based on the Redis channel mode and the Java JUC technology. The Redis channel mode can be used to replace the broadcast mode of MQ, eliminating the need to set different GROUPS for each service and enabling multi-machine deployment with a single set of code. When initiating an asynchronous task, a globally unique task identifier with business meaning is passed to the task, and the waiting thread can be accurately woken up through the task identifier subsequently.

[0048] It should be noted that in the technical solution of the present invention, aspects such as the collection, collection, update, analysis, processing, use, transmission, and storage of user personal information that may be involved all comply with the provisions of relevant laws and regulations, are used for legal purposes, and do not violate public order and good customs. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and to safeguard the security of user personal information, network security, and national security.

[0049] For the foregoing method embodiments, for the sake of description, they are expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence. In fact, some steps can be carried out in other sequences or simultaneously. In addition, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential for implementing the present invention.

[0050] To better implement the above solutions of the embodiments of the present invention, the following also provides related devices for implementing the above solutions.

[0051] Please refer to Figure 6 As shown, the task conversion device 600 provided by the embodiments of the present invention is set in the components pre-introduced into the server, and may include: an object creation unit 601, a thread blocking unit 602, and a thread wake-up unit 603.

[0052] Among them, the object creation unit 601 is used to: in response to receiving the globally unique asynchronous task identifier indicating the asynchronous task sent by the server, create a blocking object by using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; the thread blocking unit 602 is used to add a record containing the asynchronous task identifier to the local cache set of the server, and block the execution thread of the server based on the blocking object; the thread wake-up unit 603 is used to, when obtaining the task execution result message containing the target asynchronous task identifier sent by the asynchronous task execution end from a preset external middleware, determine whether the target asynchronous task identifier exists in the local cache set; if it exists, return the task execution result in the task execution result message to the server, and wake up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0053] In the embodiments of the present invention, the external middleware is implemented based on Redis; and, the thread wake-up unit 603 can be further used to: subscribe to a specific channel of the external middleware in advance, and obtain the task execution result message from the specific channel; wherein, the asynchronous task execution end, as the producer of the external middleware, sends a message to the specific channel.

[0054] As a preferred solution, the thread blocking unit 602 can be further used to: after creating the blocking object by using the asynchronous task identifier, determine the current time as the creation time of the blocking object, and store the blocking object, the creation time of the blocking object, and the asynchronous task identifier corresponding to the blocking object as a record in the local cache set.

[0055] Preferably, the thread wake-up unit 603 may further be configured to: periodically query the local cache set, and determine a timeout object for a blocked object whose execution duration is greater than a preset duration threshold when it is determined that there is a blocked object with an execution duration greater than the preset duration threshold in the local cache set; wherein, the execution duration of any blocked object is the difference between the current time and the creation time of the blocked object; return a timeout execution result of the asynchronous task identifier corresponding to the timeout object to the server, and wake up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0056] In a specific application, the thread wake-up unit 603 may further be configured to: after returning the task execution result or the timeout execution result corresponding to any asynchronous task identifier to the server, delete the record indicated by the asynchronous task identifier in the local cache set.

[0057] In addition, in the embodiment of the present invention, the task execution result includes: a task execution status with a value of success or failure; when the task execution status is success, the task execution result further includes: successfully executed data; when the task execution status is failure, the task execution result further includes: a reason for failed execution.

[0058] According to the technical solution of the embodiment of the present invention, the conversion from an asynchronous task to a synchronous task is performed by a component of a server that pre-introduces a computer cluster. After the server encounters an asynchronous task that needs to be executed by an asynchronous task execution end during operation, it sends a globally unique asynchronous task identifier to the component. The component creates a blocked object using the asynchronous task identifier, adds a record containing the asynchronous task identifier to the local cache set of the server, and blocks the execution thread of the server based on the blocked object. Thereafter, the component waits for the task execution result. When a task execution result message sent by the asynchronous task execution end and containing the target asynchronous task identifier is obtained from a preset external middleware, if it is determined that the target asynchronous task identifier exists in the local cache set, it indicates that the corresponding asynchronous task is sent by the current server, and the task execution result in the task execution result message is returned to the server, and the execution thread of the server is woken up, thereby converting the asynchronous task into a synchronous task. In this way, the accurate correspondence and association between the asynchronous task and the server during the conversion of the asynchronous task in the service cluster deployment environment are realized, and errors during the execution of the asynchronous task are avoided. In addition, Redis is used to replace the traditional message queue module to establish an external middleware from which the component obtains the message returned by the asynchronous task execution end, overcoming the defect that different groups need to be set for each service in the traditional message queue module, realizing multi-machine deployment of a set of code, and facilitating later operation and maintenance.

[0059] Figure 7An exemplary system architecture 700 to which the task transformation method or task transformation device of the embodiments of the present invention can be applied is presented.

[0060] As Figure 7 shown, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705 (this architecture is merely an example, and the components included in the specific architecture can be adjusted according to the specific situation of the application). The network 704 is used to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. The network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0061] Users can use the terminal devices 701, 702, 703 to interact with the server 705 through the network 704 to receive or send messages, etc. Various client applications, such as a task transformation application (only an example), may be installed on the terminal devices 701, 702, 703.

[0062] The terminal devices 701, 702, 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop portable computers, and desktop computers, etc.

[0063] The server 705 may be a server providing various services, such as a background server (only an example) that provides support for the task transformation application operated by the users using the terminal devices 701, 702, 703. The background server may process the received task transformation requests and feedback the processing results (such as transformation success or failure - only an example) to the terminal devices 701, 702, 703.

[0064] It should be noted that the task transformation method provided by the embodiments of the present invention is generally executed by the server 705. Correspondingly, the task transformation device is generally set in the server 705.

[0065] It should be understood that Figure 7 the numbers of the terminal devices, the network, and the server in

[0066] are merely illustrative. According to the implementation requirements, there may be any number of terminal devices, networks, and servers.

[0067] Next, reference is made to Figure 8 , which shows a schematic structural diagram of a computer system 800 of an electronic device suitable for implementing the embodiments of the present invention.Figure 8 The electronic device shown is merely an example and should not impose any limitations on the functions and scope of use of the embodiments of the present invention.

[0068] As Figure 8 shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage section 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the computer system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0069] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as required. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as required so that a computer program read therefrom is installed into the storage section 808 as required.

[0070] Specifically, according to the embodiments disclosed in the present invention, the process described in the above main step diagram can be implemented as a computer software program. For example, the embodiments of the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the method shown in the main step diagram. In the above embodiments, the computer program can be downloaded and installed from a network through the communication section 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit 801, the above functions defined in the system of the present invention are executed.

[0071] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0072] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0073] The units involved in the embodiments of the present invention can be implemented in software or in hardware. The described units can also be provided in a processor. For example, it can be described as: a processor includes an object creation unit, a thread blocking unit, and a thread wake-up unit. Among them, the names of these units do not constitute a limitation on the unit itself in some cases. For example, the object creation unit can also be described as "the unit that provides a blocking object to the thread blocking unit".

[0074] As another aspect, the present invention further provides a computer-readable medium. The computer-readable medium can be included in the device described in the above embodiments; it can also exist alone without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by the device, the steps performed by the device include: in response to receiving a globally unique asynchronous task identifier sent by the server indicating an asynchronous task, creating a blocking object using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; adding a record containing the asynchronous task identifier to the local cache set of the server, and blocking the execution thread of the server based on the blocking object; in the case of obtaining a task execution result message containing a target asynchronous task identifier sent by the asynchronous task execution end from a preset external middleware, determining whether the target asynchronous task identifier exists in the local cache set; if it exists, returning the task execution result in the task execution result message to the server, and waking up the execution thread of the server to convert the asynchronous task into a synchronous task.

[0075] In the technical solution of the embodiment of the present invention, the conversion from an asynchronous task to a synchronous task is executed by the components of the servers pre-introduced into the computer cluster. After the servers encounter an asynchronous task that needs to be executed by the asynchronous task execution end during the working process, they send a globally unique asynchronous task identifier to the components. The components create a blocking object by using the asynchronous task identifier, add a record containing the asynchronous task identifier to the local cache set of the servers, and block the execution threads of the servers based on the blocking object. Thereafter, the components wait for the task execution result. When obtaining a task execution result message sent by the asynchronous task execution end and containing the target asynchronous task identifier from the preset external middleware, if it is determined that the target asynchronous task identifier exists in the local cache set, it indicates that the corresponding asynchronous task is sent by the current server. Then, the task execution result in the task execution result message is returned to the server, and the execution threads of the servers are awakened, thereby converting the asynchronous task into a synchronous task. In this way, the accurate correspondence and association between the asynchronous task and the server during the conversion of the asynchronous task in the service cluster deployment environment are realized, and errors during the execution of the asynchronous task are avoided. In addition, Redis is used to replace the traditional message queue module to establish the external middleware from which the components obtain the messages returned by the asynchronous task execution end, overcoming the defect that different groups need to be set for each service in the traditional message queue module, realizing multi-machine deployment of a set of code, and facilitating later operation and maintenance.

[0076] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A task conversion method, characterized in that, it is executed by components pre-introduced into the server; the method includes: In response to receiving a globally unique asynchronous task identifier sent by the server indicating an asynchronous task, creating a blocking object using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; Adding a record containing the asynchronous task identifier to the local cache set of the server, and blocking the execution thread of the server based on the blocking object; When a task execution result message containing a target asynchronous task identifier sent by the asynchronous task execution end is obtained from a preset external middleware, determining whether the target asynchronous task identifier exists in the local cache set; if it exists, returning the task execution result in the task execution result message to the server, and waking up the execution thread of the server to convert the asynchronous task into a synchronous task.

2. The method according to claim 1, characterized in that, the method further includes: After creating the blocking object using the asynchronous task identifier, determining the current time as the creation time of the blocking object, and storing the blocking object, the creation time of the blocking object, and the asynchronous task identifier corresponding to the blocking object as a record in the local cache set.

3. The method according to claim 1, characterized in that, the external middleware is implemented based on Redis; and, the method further includes: Pre-subscribing to a specific channel of the external middleware, and obtaining the task execution result message from the specific channel; wherein, the asynchronous task execution end, as a producer of the external middleware, sends a message to the specific channel.

4. The method according to claim 2, characterized in that, the method further includes: Periodically querying the local cache set, and when it is determined that there is a blocking object in the local cache set whose execution duration is greater than a preset duration threshold, determining the blocking object with an execution duration greater than the preset duration threshold as a timeout object; wherein, the execution duration of any blocking object is the difference between the current time and the creation time of the blocking object; Returning a timeout execution result of the asynchronous task identifier corresponding to the timeout object to the server, and waking up the execution thread of the server to convert the asynchronous task into a synchronous task.

5. The method according to claim 4, characterized in that, the method further includes: After returning the task execution result or the timeout execution result corresponding to any asynchronous task identifier to the server, deleting the record indicated by the asynchronous task identifier in the local cache set.

6. The method according to claim 1, characterized in that, the task execution result includes: a task execution status with a value of success or failure; When the task execution status is success, the task execution result further includes: successfully executed data; When the task execution status is failure, the task execution result further includes: a reason for execution failure.

7. A task conversion device, It is characterized in that it is provided in a component pre-introduced into the server; the device includes: an object creation unit configured to: in response to receiving a globally unique asynchronous task identifier indicating an asynchronous task sent by the server, create a blocking object by using the asynchronous task identifier; wherein, the asynchronous task is initiated by the server to a preset asynchronous task execution end; a thread blocking unit configured to add a record containing the asynchronous task identifier to a local cache set of the server and block the execution thread of the server based on the blocking object; a thread wake-up unit configured to, when obtaining a task execution result message containing a target asynchronous task identifier sent by the asynchronous task execution end from a preset external middleware, determine whether the target asynchronous task identifier exists in the local cache set; if it exists, return the task execution result in the task execution result message to the server and wake up the execution thread of the server to convert the asynchronous task into a synchronous task.

8. The device according to claim 7, it is characterized in that the external middleware is implemented based on Redis; and the thread wake-up unit is further configured to: subscribe to a specific channel of the external middleware in advance and obtain the task execution result message from the specific channel; wherein, the asynchronous task execution end acts as a producer of the external middleware to send a message to the specific channel.

9. An electronic device, it is characterized in that it includes: one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, enabling the one or more processors to implement the method according to any one of claims 1-6.

10. A computer-readable storage medium, on which a computer program is stored, it is characterized in that when the program is executed by a processor, it implements the method according to any one of claims 1-6.