Asynchronous calling method, device, storage medium and electronic device
By predefined target asynchronous interfaces corresponding to different programming languages in the system and generating and executing asynchronous tasks, the problem of not supporting asynchronous calls during interaction between different programming languages is solved, and the system's task processing efficiency is improved.
Patent Information
- Application Number
- CN202110352919.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-30
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2041-03-30
AI Technical Summary
In the prior art, asynchronous calls are not supported between different programming languages during interaction, resulting in inefficient system processing.
By pre-defined target asynchronous interfaces corresponding to different programming languages, after receiving target asynchronous requests, asynchronous tasks are generated and delivered to the task pool. The tasks are executed through the asynchronous thread pool to realize asynchronous calls between different programming languages.
It improves task processing efficiency, realizes asynchronous calls during interaction between different programming languages, and avoids the blocking problems caused by synchronous calls.
Smart Images

Figure CN112988356B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an asynchronous calling method, device, storage medium and electronic device. Background Art
[0002] With the continuous development of computer technology, distributed systems have been widely used. In a distributed system, multiple nodes are set up in the system, and nodes with different functions can call each other to complete the preset functions.
[0003] In the prior art, in order to improve the processing efficiency of distributed systems, multithreading is usually used to implement asynchronous calls between nodes so that multiple nodes can run in parallel. However, the existing system architecture uses multiple programming language versions. When users call services, using synchronous calls will block the business and they need to wait for the server to complete the processing before continuing, which affects the operating efficiency. Summary of the invention
[0004] The embodiments of the present application provide an asynchronous call method, device, storage medium and electronic device, which can solve the technical problem that different programming languages do not support asynchronous calls when interacting. The technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides an asynchronous calling method, including:
[0006] Receive a target asynchronous request, and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages;
[0007] Generate a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and deliver the target asynchronous task to a task pool;
[0008] The target asynchronous task in the task pool is executed by a target asynchronous thread in the asynchronous thread pool; wherein the target asynchronous thread calls the target service when executing the target asynchronous task.
[0009] In a second aspect, an embodiment of the present application provides an asynchronous calling device, the device comprising:
[0010] A receiving module, configured to receive a target asynchronous request and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages;
[0011] A generating module, used for generating a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and delivering the target asynchronous task to a task pool;
[0012] An execution module is used to execute the target asynchronous task in the task pool through a target asynchronous thread in the asynchronous thread pool; wherein the target asynchronous thread calls the target service when executing the target asynchronous task.
[0013] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0014] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0015] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:
[0016] When the above-mentioned asynchronous call method, device, storage medium and electronic device are working, a target asynchronous request is received, a target asynchronous interface corresponding to the target asynchronous request is determined, wherein the target asynchronous interface corresponds to target services of at least two programming languages, a target asynchronous task corresponding to the target asynchronous request is generated through the target asynchronous interface, and the target asynchronous task is delivered to the task pool, and the target asynchronous task in the task pool is executed through the target asynchronous thread in the asynchronous thread pool, wherein the target asynchronous thread calls the target service when executing the target asynchronous task. In the present application, the electronic device predefines the target asynchronous interfaces corresponding to different programming languages, and after receiving the target asynchronous request, it can be directly saved to the task pool through the corresponding target asynchronous interface, and then multiple tasks can be executed simultaneously through the threads in the thread pool, thereby realizing asynchronous calls between different programming languages during interaction and improving task processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 It is a schematic diagram of a network architecture of a calling system provided in an embodiment of the present application;
[0019] Figure 2 It is a flowchart of an asynchronous calling method provided in an embodiment of the present application;
[0020] Figure 3This is another flowchart of an asynchronous calling method provided by an embodiment of the present application;
[0021] Figure 4 This is a schematic diagram of a task pool and a thread pool provided in an embodiment of the present application;
[0022] Figure 5 This is a schematic diagram of an acquisition request provided in an embodiment of the present application;
[0023] Figure 6 This is a schematic diagram of the correspondence between a language type and an asynchronous interface provided in an embodiment of the present application;
[0024] Figure 7 This is a task pool delivery schematic diagram provided in an embodiment of the present application;
[0025] Figure 8 It is a thread state diagram provided by an embodiment of the present application;
[0026] Fig. 9 This is a task blocking delivery diagram provided by an embodiment of the present application;
[0027] Fig.10 It is a structural diagram of an asynchronous calling device provided in an embodiment of the present application;
[0028] Fig.11 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0029] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0030] When the following description is designed with drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0031] In the description of this application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previously associated objects are in an "or" relationship.
[0032] The present application is described in detail below with reference to specific embodiments.
[0033] Figure 1 An exemplary system architecture 100 that can be applied to the asynchronous calling method of the present application is shown.
[0034] like Figure 1 As shown, the system architecture 100 may include a user 101, an electronic device 102, and a network 103. The network 103 is used to provide a medium for a communication link between the user 101 and the electronic device 102. Among them, the system architecture 100 can be applied to various practical application scenarios. For example, when the system architecture 100 is applied to online live broadcasting, the user 101 can be a teacher or student or a student's parent in an online live broadcast course, as well as R&D personnel of various departments, etc. The user 101 can be used to trigger various instructions on the electronic device 102, and the electronic device 102 can be a teacher client, a student client, and a server end providing services in the background, etc. The electronic device 102 can be responsible for reading various instructions triggered by the user 101, decoding the instructions and executing the instructions. Exemplarily, in the process of conducting an online live broadcast course, the user 101 (for example, but not limited to teacher A) arranges an online exam, and then requires students to submit electronic test papers within a specified time, and the teacher client performs online marking. The automatic marking system in the teacher client may be composed of a Grpc system framework, including multiple programming languages such as golang and python for programming, and interactively providing call services. Multiple users 101 (such as but not limited to student A and student B) can simultaneously click the load button with the mouse to trigger the upload of the test paper electronic document 1 service, and then the electronic device 102 (such as but not limited to the teacher client) simultaneously obtains the grading request of the test paper electronic document 1, in order to improve the efficiency of the online live course. The electronic device needs to asynchronously process multiple test paper grading requests, then the electronic device can call the corresponding asynchronous interface to encapsulate the multiple grading requests into multiple corresponding asynchronous tasks, deliver them to the task pool, and then process the multiple asynchronous tasks simultaneously through multiple threads in the thread pool, and finally send the grading results to each student and other related operations.
[0035] The electronic device 102 may be hardware or software. When the electronic device 102 is hardware, it may be various electronic devices with the function of calling asynchronous collections, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers. When the electronic device 102 is software, it may be implemented as multiple software or software modules (for example, to provide asynchronous call services), or it may be implemented as a single software or software module, which is not specifically limited here.
[0036] The network 103 may include various types of wired communication links or wireless communication links, and the user 101 and the electronic device 102 may exchange data through the network 103. For example, the wired communication link may include optical fiber, twisted pair or coaxial cable, and the wireless communication link may include Bluetooth communication link, Wireless-Fidelity (Wi-Fi) communication link or microwave communication link.
[0037] It should be understood that Figure 1 The number of users 101, electronic devices 102 and networks 103 in FIG. 1 is only illustrative. Depending on the implementation requirements, there may be any number of users 101, electronic devices 102 and networks 103.
[0038] In the following method embodiments, for the sake of convenience, only the electronic device is used as the execution subject of each step for introduction and description.
[0039] The following will be combined with the attached Figures 2 to 3 , the asynchronous calling method provided in the embodiment of the present application is introduced in detail.
[0040] See also Figure 2 , provides an interactive schematic diagram of an asynchronous calling method for an embodiment of the present application. The method may include the following steps:
[0041] S201: Receive a target asynchronous request, and determine a target asynchronous interface corresponding to the target asynchronous request.
[0042] Generally, a request may refer to a message or instruction that an electronic device needs to receive in order to meet different user needs, so that the electronic device can perform corresponding tasks / operations / steps and other services, and may include a request method for electronic device resources, resource identifiers, and protocols used. User-triggered requests may include synchronous requests and asynchronous requests. A synchronous request may refer to an electronic device being in a waiting state during the processing of a task. The electronic device needs to process the only current task and respond to the user with the processing result before continuing to process requests for other tasks, that is, while processing one task, it will block the processing of other tasks. An asynchronous request may refer to an electronic device being able to perform other tasks normally while executing the current task, which helps the efficiency of business processing by the electronic device and improves the user experience. For example: in a live course of online education, online invigilation, multi-person live broadcast and other request services on the teacher side, and courseware loading, audio and video upload and other request services on the student side can all be set as asynchronous requests because they need to reflect real-time and high efficiency.
[0043] The target asynchronous request may be any asynchronous request received by the electronic device. The target asynchronous request here does not specifically refer to a certain type or a class of specific asynchronous requests, and is not specifically limited. It may be an asynchronous request obtained for the user's current operation, in order to distinguish it from other asynchronous requests for other purposes that are being executed.
[0044] There are many ways for electronic devices to receive target asynchronous requests, which are not specifically limited in this application. For example, an electronic device can receive target asynchronous requests sent by other electronic devices (such as but not limited to student clients and teacher clients, etc.), or it can be a request generated by a user by operating a keyboard, mouse, or screen in an electronic device in order to trigger the loading of a service. For example, in the process of a live online course, in order to complete the service of loading the audio and video, student A can click the load button with his finger, and then the electronic device detects the interactive operation of student A, and then obtains the target asynchronous request of the corresponding service, and completes the service of loading the audio and video based on the target asynchronous request. In a possible embodiment, the target asynchronous request can also be generated according to a preset time or time period. For example, in the process of a live online course, when the electronic device detects that this English class has been going on for 10 minutes, the electronic device can query in a pre-defined service and time correspondence table to determine the service that needs to be completed at this time (such as but not limited to loading classroom test question 1), and then obtain the corresponding target asynchronous request based on the service.
[0045] After the electronic device receives the target asynchronous request, it can determine the target asynchronous interface corresponding to the target asynchronous request. The asynchronous interface can be considered to refer to the reference type that defines the protocol. The interface can improve the reuse rate of program code and increase the maintainability and scalability of the program. The asynchronous interface is matched with the above-mentioned asynchronous requests so that other events or programs can directly call the corresponding service for each asynchronous request through the asynchronous interface. There may be many ways to determine the asynchronous interface corresponding to the asynchronous request. For example, the electronic device can determine the asynchronous interface corresponding to the asynchronous request through the identifier carried in the asynchronous request, and can also determine the asynchronous interface corresponding to the asynchronous request through the programming language type corresponding to the asynchronous request. It can also determine the asynchronous interface corresponding to the asynchronous request through the service resources of the target service corresponding to the asynchronous request. The present application may not limit the method of determining the asynchronous interface corresponding to the asynchronous request.
[0046] The target asynchronous interface corresponds to target services of at least two programming languages. The programming language can be simply understood as a language that can be recognized by both computers and humans. A computer language allows programmers to accurately define the data needed by the computer and accurately define the actions to be taken in different situations, such as: go language, python language, swift language, c language, c++ language and java language. Service can refer to tasks / operations / steps that electronic devices need to perform to meet different user needs. The target service here does not necessarily refer to a specific service (or a class of services), and there is no specific limitation, but it can refer to a service determined for the user's current operation, in order to distinguish it from other services being executed. Target services can include: application services, web services, database services and communication services, etc. For example: Student A needs to load a section of audio and video to explain the knowledge points in detail during the online live course. For the electronic device, loading the audio and video can be used as a target service. Since different language types have different characteristics, multiple languages are usually used in the prior art to jointly develop a framework. During the interaction between different languages, asynchronous calling services may not be supported. Therefore, the present application is aimed at electronic devices that call services in at least two programming languages by calling corresponding asynchronous interfaces to perform relevant processing, thereby enabling asynchronous calls.
[0047] S202: Generate a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and deliver the target asynchronous task to a task pool.
[0048] Generally, an asynchronous task may refer to a task corresponding to an asynchronous request. The asynchronous task may only include the content of the asynchronous request or other content, and may be customized according to actual user needs. For example, during live online education, the electronic device may directly convert the request format (such as but not limited to electrical signals) of student A to query the course schedule into the task format (such as but not limited to analog signals) of querying the course schedule, and generate a corresponding asynchronous task. The electronic device may also generate a corresponding asynchronous task together with student A's request to query the course schedule and the corresponding communication protocol or log files. There is a corresponding relationship between asynchronous tasks and asynchronous interfaces. For example, the electronic device may set a corresponding table between asynchronous tasks and asynchronous interfaces, and the electronic device may also make a judgment based on the common identification of asynchronous tasks and asynchronous interfaces.
[0049] The target asynchronous task can be any asynchronous task acquired by the electronic device. The target asynchronous task here does not specifically refer to a certain type or a class of specific asynchronous tasks, and is not specifically limited. It can be an asynchronous task acquired for the user's current operation, in order to distinguish it from other asynchronous tasks for other purposes being executed, and in order to correspond to the target asynchronous request.
[0050] There are various ways for electronic devices to generate target asynchronous tasks corresponding to the target asynchronous requests. For example, the electronic device can set local preset generation rules to generate the target asynchronous tasks corresponding to the target asynchronous requests. The preset generation rules can be updated, deleted, and added in real time through user instructions. The electronic device can also quickly and intelligently generate the target asynchronous tasks corresponding to the target asynchronous requests by calling a generation module deployed in the cloud (for example, but not limited to a model server, etc.).
[0051] The task pool may refer to a component of the business layer in the electronic device that stores tasks, a container for tasks, and an instance pool for sharing tasks between threads. It is completely transparent to the client layer, for example: the task pool may be in the form of a queue, a table, a database, etc. When the electronic device application is started, the task pool is created and cleared when it stops. Due to the cache mechanism for tasks provided by the task pool, the system overhead generated by frequently creating and recycling task instances can be reduced, and storage resources can be saved. After the electronic device generates the target asynchronous task corresponding to the target asynchronous request, the storage address of the task pool can be obtained first, and then the electronic device can store the target asynchronous task in the storage space corresponding to the storage address of the task pool. The number of the task pools may be one or more, and an appropriate amount of task pools may be set according to the actual task amount, which helps to improve the operating efficiency of the electronic device. The task pool may be stored locally in the electronic device, or uploaded to the cloud (for example, but not limited to a storage server), and then the electronic device may interact through data transmission, which helps to reduce the storage space of the electronic device and increase the operating efficiency.
[0052] S203. Execute the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool.
[0053] Generally, a thread pool refers to a container for a thread usage pattern. In actual use, too many threads will bring scheduling overhead, which will affect cache locality and overall performance. The thread pool maintains multiple threads, waiting for the supervisor to assign concurrently executable tasks. This avoids the cost of creating and destroying threads when processing short-time tasks. The thread pool can not only ensure full utilization of the core, but also prevent over-scheduling. The number of available threads should depend on the number of available concurrent processors, processor cores, memory, network programming interfaces, etc. For example, the number of threads is generally more appropriate to take the number of CPUs + 2. Too many threads will lead to additional thread switching overhead.
[0054] The asynchronous thread pool can be understood as a thread pool that is specifically used by electronic devices to process asynchronous tasks. This is to distinguish it from the synchronous thread pool. The number, capacity, and specific form of the asynchronous thread pool are not specifically limited, and can be customized by the user in real time according to actual usage. An asynchronous thread can refer to a thread in the asynchronous thread pool that specifically processes the target asynchronous task. The target asynchronous thread can be any asynchronous thread generated by the electronic device. The target asynchronous thread here does not specifically refer to a certain type or class of specific asynchronous threads, and is not specifically limited. It can be an asynchronous thread generated for the user's current operation, in order to distinguish it from other asynchronous threads that are being executed for other purposes, and in order to correspond to the target asynchronous task.
[0055] After the electronic device delivers the target asynchronous task to the task pool, it can then execute the target asynchronous tasks in the task pool sequentially according to the task execution order. For example, the electronic device can call the target service when executing the target asynchronous task through the target asynchronous thread in the asynchronous thread pool to complete the target asynchronous task. This helps the electronic device to implement asynchronous calls when interacting between different programming languages. For example, there are 5 asynchronous tasks in the task pool (including the target asynchronous task, numbered 3), and there are 4 in the thread pool and they are all idle. Then the electronic device executes the target asynchronous task numbered 3 through the target asynchronous thread numbered 3, and task No. 5 needs to wait for the other 4 threads to be processed before it can be processed.
[0056] It can be seen from the above content that a target asynchronous request is received, a target asynchronous interface corresponding to the target asynchronous request is determined, wherein the target asynchronous interface corresponds to target services of at least two programming languages, a target asynchronous task corresponding to the target asynchronous request is generated through the target asynchronous interface, and the target asynchronous task is delivered to the task pool, and the target asynchronous task in the task pool is executed through the target asynchronous thread in the asynchronous thread pool, wherein the target asynchronous thread calls the target service when executing the target asynchronous task. In the present application, the electronic device predefines the target asynchronous interfaces corresponding to different programming languages, and after receiving the target asynchronous request, it can be directly saved to the task pool through the corresponding target asynchronous interface, and then multiple tasks can be executed simultaneously through the threads in the thread pool, thereby realizing asynchronous calls between different programming languages during interaction and improving task processing efficiency.
[0057] See also Figure 3 , another interactive schematic diagram of an asynchronous call method is provided for an embodiment of the present application. The asynchronous call method may include the following steps:
[0058] S301: Acquire a programming language type of a system framework, and generate an asynchronous interface set based on the programming language type.
[0059] Generally, the system framework can refer to the technical implementation framework and planning of the determined requirements, and the use of complete sets of tools to complete the tasks in the planned steps. In abstract terms, it is the computer system structure, or computer architecture, which is the highest-level concept of a system in its environment, determining the connection between a computer hardware and software. Specifically, the electronic equipment architecture refers to the concept and architecture of the electronic equipment system design, describing the design principles of the computer in practice, etc. For example: in the online live education industry, resource management framework, multi-person online live framework and stress testing and debugging framework. Programming language types can include: go language, python language, swift language, c language, c++ language and java language, etc. Electronic devices can design and implement system architecture through multiple programming languages. Asynchronous interface set can refer to the whole composed of one or more determined asynchronous interfaces, for example: electronic devices can represent the asynchronous interface set by setting an asynchronous interface table, and electronic devices can also determine the path of each asynchronous interface to determine the asynchronous interface set. The form, quantity, and logical relationship of the asynchronous interface set are not specifically limited.
[0060] In the present application, the electronic device can first obtain the programming language type of the system framework, and generate an asynchronous interface set based on the programming language type. For example, the electronic device can generate go language and python language, python language and swift language, and multiple asynchronous interfaces such as go language, python language and swift language through the three language types of go language, python language and swift language actively input by the technician, wherein the number of language types corresponding to the asynchronous interface is not specifically limited, and can be two, three, four, etc., and can be customized by the user in real time according to the actual situation. In a possible embodiment, the electronic device can also automatically search for the language tags of the components of the local system architecture to obtain the programming language type of the system framework, and the electronic device can also crawl multiple language types on the Internet to preset the asynchronous interfaces that may be used, etc. The electronic device can store the asynchronous interface set locally, or store it in other devices such as the cloud, which helps to improve the operating efficiency of the electronic device, save time, and improve the user experience.
[0061] S302, detecting whether the task pool and the asynchronous thread pool are initialized. If the task pool and the asynchronous thread pool are not initialized, obtaining initialization configuration information, and initializing the task pool and the asynchronous thread pool according to the initialization configuration information.
[0062] Generally, initialization in the field of computer programming can refer to assigning initial values to data objects or variables. In electronic devices, assigning initial values to each variable is considered a good programming habit, which helps to reduce the possibility of errors. Initialization configuration information can refer to initialization parameters when configuring a task pool or a thread pool, etc., which can include a maximum value of the number of cores, a maximum value of the total number, a non-core idle timeout duration, a maximum number of concurrent connections, a unified encoding, a data entry and exit method (such as but not limited to first-in-first-out, first-in-last-out, etc.), a task pool threshold, a task queue, and a rejection strategy, etc. After generating an asynchronous interface set, the electronic device can detect whether the task pool and the asynchronous thread pool are initialized, for example: the electronic device can obtain a delegate notification in the task pool and the asynchronous thread pool, or determine the monitoring return value, or traverse the task list to determine whether it is initialized. If the task pool and the asynchronous thread pool are not initialized, the initialization configuration information is obtained, for example, the electronic device determines that the number of core tasks in the task pool is 5, the number of non-core tasks is 3, the task pool threshold is 6, the entry and exit method is first-in-first-out, and the timeout blocking time is often 60 seconds. Then the electronic device performs initialization processing on the task pool and the asynchronous thread pool according to the initialization configuration information, which helps the electronic device reduce operation errors and improve operation stability. Figure 4As shown, there can be multiple tasks in the task pool, and then there can be multiple threads in the asynchronous thread pool. The electronic device pre-sets the execution strategy through the system framework (such as but not limited to the Executor framework), and each thread executes the corresponding task, for example: thread 1 processes task 1, thread 2 processes task 2, thread 3 processes task 3, etc. Each thread is associated with a corresponding kernel thread, and then the central processing unit resources are scheduled through the thread scheduler on the electronic device (such as but not limited to the OS Kernel). Each thread will eventually be mapped to the central processing unit for processing. If the central processing unit has multiple cores, multiple thread tasks can be executed in parallel.
[0063] S303: Receive a target asynchronous request, parse the target asynchronous request to determine a target programming language type, and query a corresponding target asynchronous interface in the asynchronous interface set based on the target programming language type.
[0064] In general, such as Figure 5 As shown, the user can first select the resource data to be uploaded (such as but not limited to file 1), and then upload file 1 to the electronic device by clicking the "Confirm Upload" button on the electronic device display screen, that is, the electronic device receives the request to upload the resource data. After receiving the request, the electronic device also needs to determine the request type of the request, and then substitute different interfaces. For example: the electronic device can determine the request type by parsing the file header of the request through the header parameters. If the keyword async is true, the electronic device can be determined as an asynchronous request. If it is false, the electronic device can be determined as, and then the electronic device can also be determined by the request type flag set by the starter. The electronic device then parses the target asynchronous request to determine the target programming language type, and queries the corresponding target asynchronous interface in the asynchronous interface set based on the target programming language type. For example: the electronic device determines that the target programming language type is go language and python language, then the electronic device can traverse and query the corresponding target asynchronous interface A in the asynchronous interface set, or it can determine the corresponding target asynchronous interface A by the target programming language type number, which helps the electronic device to quickly and accurately determine the corresponding asynchronous interface. As Figure 6 As shown, the electronic device can set a correspondence between the language type and the asynchronous interface. For example: if the service involves two types, namely, the go language type and the python language type, then it corresponds to asynchronous interface 1; if the service involves two types, namely, the c language type and the java language type, then it corresponds to asynchronous interface 2; if the service involves three types, namely, the VB language type, the PHP language type and the C# language type, then it corresponds to asynchronous interface 3, and so on.
[0065] S304: Encapsulate the request body and callback function of the target asynchronous request into a corresponding target asynchronous task through the target asynchronous interface.
[0066] Generally, a request may include a request line, a request header and a request body. The request line may mainly include information such as the request method, the request address, the protocol and the version. The request header may mainly include the content type that can be received, one or more sub-range fields of the requested web page entity, the cache mechanism and the authorized authorization certificate that the specified request and response follow, and the request body may mainly include information such as the service type that the request needs to call. The callback function can be considered as a function that is passed as a parameter. The use of the callback function can greatly improve the efficiency of programming, which makes it very widely used in modern programming. At the same time, the use of the callback function can realize some special requirements. Encapsulation can be considered to hide the properties and implementation details of the object, only open the interface to the outside, control the access level of the read and modify properties in the program, combine the abstracted data and behavior (or function) to form an organic whole, and can also be considered to be an organic combination of data and the source code of the operation data to form a "class", in which data and functions are members of the class. After the electronic device queries the corresponding target asynchronous interface, the request body and callback function of the target asynchronous request can be encapsulated into the corresponding target asynchronous task through the target asynchronous interface, wherein the callback function at least includes a success callback function and a failure callback function.
[0067] S305: Determine whether the usage in the task pool is less than the task pool threshold; if not, perform timeout blocking processing on the target asynchronous task.
[0068] Generally, after the electronic device encapsulates the request body and callback function of the target asynchronous request into the corresponding target asynchronous task, it needs to determine whether the usage in the task pool is less than the task pool threshold. For example, the electronic device pre-sets the task pool threshold of the task pool to 10, determines that the usage in the current task pool is 10, and determines that it is not less than, it is necessary to perform timeout blocking processing on the target asynchronous task, and set the timeout blocking duration to 3 minutes. If there is no idle usage in the current task pool within 3 minutes, the electronic device can adopt a timeout strategy (for example, but not limited to discarding the task or taking out other tasks with high priority in the task pool, etc.). If the electronic device determines that it is less than, the target asynchronous task is directly delivered to the task pool.
[0069] S306: When the number of tasks in the task pool is less than or equal to the task pool threshold, the target asynchronous task of the timeout blocking process is delivered to the task pool.
[0070] Generally, if the electronic device determines that the number of tasks in the task pool is less than or equal to the task pool threshold, the target asynchronous task of the timeout blocking process is delivered to the task pool. Figure 7As shown, when the task pool threshold is 4, there are two tasks in the current task pool, namely, asynchronous task 1 and asynchronous task 2, which are smaller than the task pool threshold, and then the electronic device can directly deliver asynchronous task 3 to the task pool.
[0071] S307: Determine the running status of all asynchronous threads in the asynchronous thread pool, and use an asynchronous thread in an idle state in the asynchronous thread pool as a target asynchronous thread.
[0072] Generally, an asynchronous thread can be understood as the smallest unit of device resources for processing tasks and performing calculation scheduling, etc. The running state (life cycle) of an asynchronous thread can include a newly created state, an executable state, an operating state, a blocked state, and a dead state, etc. After the electronic device delivers the target asynchronous task to the task pool, it needs to determine the running state of all asynchronous threads in the asynchronous thread pool. For example, the electronic device can identify the running state of all asynchronous threads in the asynchronous thread pool by calling the isAlive function, etc., and then determining the return value. If it is executable or blocked, the function returns true; if the thread is still in a newly created state and is not executable, or the thread is dead, the function returns false. Figure 8 As shown in the figure, when a thread is created with the operator new, such as new Thread(r), the thread has not started running yet. At this time, the thread is in the newly created state. When a thread is in the newly created state, the program has not started running the code in the thread. Then a newly created thread does not start running automatically. To execute the thread, the thread function start() must be called. When the thread object calls the start() function, the thread is started. The start() function creates system resources for the thread to run and schedules the thread to run the run() function. When the start() method returns, the thread is in the ready state. Then, when the thread obtains the CPU time, the thread enters the running state and actually starts to execute the run() function. Then, during the running process of the thread, it may enter the blocked state due to various reasons, such as: the thread is waiting for a trigger condition, the thread enters the sleep state by calling the sleep method, and the thread calls an operation that is blocked on the input / output, etc. The so-called blocked state is that the running thread has not finished running and temporarily gives up the CPU resources. At this time, other threads in the ready state can obtain the CPU time and enter the running state. Then the thread dies naturally due to the normal exit of the run() function or an uncaught exception terminates the run() function, causing the thread to die suddenly, resulting in the thread being in a dead state. The electronic device can determine whether the thread is currently alive (that is, either executable or blocked) by calling the isAlive function and then judging the return value.
[0073] S308: taking out the target asynchronous task from the task pool through the target asynchronous thread, parsing the target asynchronous task through the target asynchronous thread to determine the target service, and loading the target service.
[0074] Generally, after the electronic device determines the target asynchronous thread, it can take out the target asynchronous task from the task pool through the target asynchronous thread, parse the target asynchronous task through the target asynchronous thread to determine the target service, and load the target service. For example: the electronic device determines that thread 3 in the thread pool is the target asynchronous thread, then takes out the target asynchronous task A in the task pool, and then parses it to determine that the target service is to load the loading file 1 written in the go language and the interface display control 3 written in the python language, and finally calls the corresponding loading resources to load the two services of loading file 1 and interface display control 3.
[0075] S309: Obtain the loading result, and execute the callback function according to the loading result.
[0076] Generally, after the electronic device loads the target service, it can obtain the loading result. If the loading is successful, the electronic device executes the success callback function and continues to process the subsequent business logic. If the loading fails, the electronic device can detect abnormal loading (for example, but not limited to repeated loading for a preset number of times). If it still fails in the end, it can also collect the loading failure parameters, execute the failure callback function based on the loading failure parameters, and perform subsequent related logic business processing. Among them, the function parameters and return values of the callback function can be customized according to the actual user usage. The number and type of settings, etc.
[0077] S310, detecting whether there is currently an asynchronous task that is blocked due to timeout, and if so, delivering the asynchronous task with the longest time of blocking due to timeout to the task pool.
[0078] Generally, after the electronic device executes the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool, it needs to detect whether there is an asynchronous task that is blocked by timeout. If so, the asynchronous task with the longest timeout blocking processing time is delivered to the task pool under the condition that the timeout duration is met. In a possible embodiment, the electronic device can also determine the asynchronous task to be delivered to the task pool based on information such as the asynchronous task type, task size, or historical task type. Fig. 9 As shown, when the current number of tasks in the task pool reaches the task pool threshold, the tasks (such as but not limited to asynchronous task 5 and asynchronous task 6) can be placed in the blocking queue and wait to be delivered to the task pool. When the current number of tasks in the task pool is less than the task pool threshold, the asynchronous tasks (such as but not limited to asynchronous task 5) in the blocking queue can be placed in the task pool.
[0079] When the scheme of the embodiment of the present application is executed, a target asynchronous request is received, a target asynchronous interface corresponding to the target asynchronous request is determined, wherein the target asynchronous interface corresponds to target services of at least two programming languages, a target asynchronous task corresponding to the target asynchronous request is generated through the target asynchronous interface, and the target asynchronous task is delivered to the task pool, and the target asynchronous task in the task pool is executed through the target asynchronous thread in the asynchronous thread pool, wherein the target asynchronous thread calls the target service when executing the target asynchronous task. In the present application, the electronic device predefines the target asynchronous interfaces corresponding to different programming languages, and after receiving the target asynchronous request, it can be directly saved to the task pool through the corresponding target asynchronous interface, and then multiple tasks can be executed simultaneously through the threads in the thread pool, thereby realizing asynchronous calls between different programming languages during interaction and improving task processing efficiency.
[0080] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0081] See also Fig.10 , which shows a schematic diagram of the structure of an asynchronous calling device provided by an exemplary embodiment of the present application, hereinafter referred to as the calling device 10. The calling device 10 can be implemented as all or part of the terminal through software, hardware or a combination of both. It includes:
[0082] The receiving module 1001 is used to receive a target asynchronous request and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages;
[0083] A generating module 1002 is used to generate a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and deliver the target asynchronous task to a task pool;
[0084] The execution module 1003 is used to execute the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool; wherein, the target asynchronous thread calls the target service when executing the target asynchronous task.
[0085] In a possible embodiment, the calling device 10 further includes:
[0086] The first acquisition module is used to acquire the programming language type of the system framework and generate an asynchronous interface set based on the programming language type.
[0087] In a possible embodiment, the receiving module 1001 includes:
[0088] A parsing unit, configured to parse the target asynchronous request to determine a target programming language type;
[0089] A query unit is used to query the corresponding target asynchronous interface in the asynchronous interface set based on the target programming language type.
[0090] In a possible embodiment, the calling device 10 further includes:
[0091] The first detection module is used to detect whether the task pool and the asynchronous thread pool are initialized;
[0092] A second acquisition module is used to acquire initialization configuration information if the task pool and the asynchronous thread pool are not initialized; wherein the initialization configuration information at least includes a task pool threshold;
[0093] A processing module is used to initialize the task pool and the asynchronous thread pool according to the initialization configuration information.
[0094] In a possible embodiment, the generating module 1002 includes:
[0095] The encapsulation unit is used to encapsulate the request body and callback function of the target asynchronous request into a corresponding target asynchronous task through the target asynchronous interface; wherein the callback function at least includes a success callback function and a failure callback function.
[0096] In a possible embodiment, the generating module 1002 includes:
[0097] A judging unit, used to judge whether the usage in the task pool is less than the task pool threshold;
[0098] A blocking unit, used for performing a timeout blocking process on the target asynchronous task if it is not less than;
[0099] The delivery unit is used to deliver the target asynchronous task of timeout blocking processing to the task pool when the number of tasks in the task pool is less than or equal to the task pool threshold.
[0100] In a possible embodiment, the execution module 1003 includes:
[0101] A first determining unit, used to determine the running status of all asynchronous threads in the asynchronous thread pool;
[0102] A second determining unit is used to use an asynchronous thread in an idle state in the asynchronous thread pool as a target asynchronous thread;
[0103] The fetching unit is used to fetch the target asynchronous task from the task pool through the target asynchronous thread and execute the target asynchronous task.
[0104] In a possible embodiment, the execution module 1003 includes:
[0105] A loading unit, configured to parse the target asynchronous task through the target asynchronous thread to determine the target service, and load the target service;
[0106] The execution unit is used to obtain the loading result and execute the callback function according to the loading result.
[0107] In a possible embodiment, the calling device 10 further includes:
[0108] The second detection module is used to detect whether there is an asynchronous task that is currently blocked by a timeout;
[0109] The delivery module is used to deliver the asynchronous task with the longest timeout blocking processing time to the task pool if it exists.
[0110] The embodiments of this application and Figures 2 to 3 The method embodiments are based on the same concept, and the technical effects they bring are also the same. The specific process can be referred to Figures 2 to 3 The description of the method embodiment will not be repeated here.
[0111] The device 10 can be a field-programmable gate array (FPGA), a dedicated integrated chip, a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processing circuit, a microcontroller unit (MCU), and a programmable logic device (PLD) or other integrated chips.
[0112] When the scheme of the embodiment of the present application is executed, a target asynchronous request is received, a target asynchronous interface corresponding to the target asynchronous request is determined, wherein the target asynchronous interface corresponds to target services of at least two programming languages, a target asynchronous task corresponding to the target asynchronous request is generated through the target asynchronous interface, and the target asynchronous task is delivered to the task pool, and the target asynchronous task in the task pool is executed through the target asynchronous thread in the asynchronous thread pool, wherein the target asynchronous thread calls the target service when executing the target asynchronous task. In the present application, the electronic device predefines the target asynchronous interfaces corresponding to different programming languages, and after receiving the target asynchronous request, it can be directly saved to the task pool through the corresponding target asynchronous interface, and then multiple tasks can be executed simultaneously through the threads in the thread pool, thereby realizing asynchronous calls between different programming languages during interaction and improving task processing efficiency.
[0113] The present application also provides a computer storage medium, which can store multiple instructions, which are suitable for being loaded by a processor and executing the above method steps. The specific execution process can be seen in Figure 2 or Figure 3 The specific description of the illustrated embodiment will not be repeated here.
[0114] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the template control method described in the above embodiments.
[0115] See also Fig.11 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.11 As shown, the electronic device 11 may include: at least one processor 1101 , at least one network interface 1104 , a user interface 1103 , a memory 1105 , and at least one communication bus 1102 .
[0116] The communication bus 1102 is used to realize the connection and communication between these components.
[0117] The user interface 1103 may include a display screen (Display) and a camera (Camera), and the optional user interface 1103 may also include a standard wired interface and a wireless interface.
[0118] The network interface 1104 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0119] Among them, the processor 1101 may include one or more processing cores. The processor 1101 uses various interfaces and lines to connect various parts of the entire terminal 1100, and executes various functions and processes data of the terminal 1100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1105, and calling data stored in the memory 1105. Optionally, the processor 1101 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1101 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1101, and it can be implemented separately through a chip.
[0120] Among them, the memory 1105 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 1105 includes a non-transitory computer-readable storage medium. The memory 1105 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1105 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1105 may also be optionally at least one storage device located away from the aforementioned processor 1101. As Fig.11 As shown, the memory 1105 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an asynchronous calling application program.
[0121] exist Fig.11In the electronic device 1100 shown, the user interface 1103 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 1101 can be used to call the asynchronous call application stored in the memory 1105, and specifically perform the following operations:
[0122] Receive a target asynchronous request, and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages;
[0123] Generate a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and deliver the target asynchronous task to a task pool;
[0124] The target asynchronous task in the task pool is executed by a target asynchronous thread in the asynchronous thread pool; wherein the target asynchronous thread calls the target service when executing the target asynchronous task.
[0125] In one embodiment, before the processor 1101 executes the receiving target asynchronous request, it is further configured to execute:
[0126] The programming language type of the system framework is obtained, and an asynchronous interface set is generated based on the programming language type.
[0127] In one embodiment, when the processor 1101 executes the step of determining the target asynchronous interface corresponding to the target asynchronous request, the processor 1101 specifically executes:
[0128] Parsing the target asynchronous request to determine the target programming language type;
[0129] The corresponding target asynchronous interface is queried in the asynchronous interface set based on the target programming language type.
[0130] In one embodiment, before the processor 1101 executes the receiving target asynchronous request, it is further configured to execute:
[0131] Check whether the task pool and asynchronous thread pool are initialized;
[0132] If the task pool and the asynchronous thread pool are not initialized, initialization configuration information is obtained; wherein the initialization configuration information at least includes a task pool threshold;
[0133] The task pool and the asynchronous thread pool are initialized according to the initialization configuration information.
[0134] In one embodiment, when the processor 1101 executes the target asynchronous task corresponding to the target asynchronous request generated through the target asynchronous interface, the processor 1101 specifically executes:
[0135] The request body and callback function of the target asynchronous request are encapsulated as a corresponding target asynchronous task through the target asynchronous interface; wherein the callback function at least includes a success callback function and a failure callback function.
[0136] In one embodiment, when the processor 1101 executes the delivering of the target asynchronous task to the task pool, the processor 1101 specifically executes:
[0137] Determine whether the usage in the task pool is less than the task pool threshold;
[0138] If it is not less than, the target asynchronous task is blocked by timeout;
[0139] When the number of tasks in the task pool is less than or equal to the task pool threshold, the target asynchronous task of the timeout blocking process is delivered to the task pool.
[0140] In one embodiment, when the processor 1101 executes the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool, the processor 1101 specifically executes:
[0141] Determine the running status of all asynchronous threads in the asynchronous thread pool;
[0142] Taking an asynchronous thread in an idle state in the asynchronous thread pool as a target asynchronous thread;
[0143] The target asynchronous task is taken out from the task pool by the target asynchronous thread, and the target asynchronous task is executed.
[0144] In one embodiment, when the processor 1101 executes the target asynchronous task, it specifically performs:
[0145] Parsing the target asynchronous task through the target asynchronous thread to determine the target service, and loading the target service;
[0146] Obtain the loading result, and execute the callback function according to the loading result.
[0147] In one embodiment, after executing the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool, the processor 1101 is further configured to execute:
[0148] Check whether there is an asynchronous task that is currently blocked by timeout;
[0149] If it exists, the asynchronous task with the longest timeout blocking processing time is delivered to the task pool.
[0150] The technical concept and Figure 2 or Figure 3The technical concept is the same as that of Figure 2 or Figure 3 The method embodiments are not described in detail here.
[0151] In an embodiment of the present application, a target asynchronous request is received, a target asynchronous interface corresponding to the target asynchronous request is determined, wherein the target asynchronous interface corresponds to target services of at least two programming languages, a target asynchronous task corresponding to the target asynchronous request is generated through the target asynchronous interface, and the target asynchronous task is delivered to a task pool, and the target asynchronous task in the task pool is executed through a target asynchronous thread in an asynchronous thread pool, wherein the target asynchronous thread calls the target service when executing the target asynchronous task. In the present application, the electronic device predefines target asynchronous interfaces corresponding to different programming languages, and after receiving a target asynchronous request, it can be directly saved to the task pool through the corresponding target asynchronous interface, and then multiple tasks can be executed simultaneously through threads in the thread pool, thereby realizing asynchronous calls between different programming languages during interaction and improving task processing efficiency.
[0152] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0153] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. An asynchronous calling method, characterized in that: The method comprises: Receive a target asynchronous request, and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages, the target asynchronous request includes a target programming language type, and a plurality of the target asynchronous interfaces constitute an asynchronous interface set; Generate a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and deliver the target asynchronous task to a task pool; Executing the target asynchronous task in the task pool through a target asynchronous thread in the asynchronous thread pool; wherein the target asynchronous thread calls the target service when executing the target asynchronous task; The determining the target asynchronous interface corresponding to the target asynchronous request includes: Parsing the target asynchronous request to determine the target programming language type; Querying the corresponding target asynchronous interface in the asynchronous interface set based on the target programming language type; The generating a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface includes: Encapsulating the request body and callback function of the target asynchronous request into a corresponding target asynchronous task through the target asynchronous interface; wherein the callback function at least includes a success callback function and a failure callback function, and the request body includes the service type that the asynchronous request needs to call; Before receiving the target asynchronous request, the method further includes: Check whether the task pool and asynchronous thread pool are initialized; If the task pool and the asynchronous thread pool are not initialized, initialization configuration information is obtained; wherein the initialization configuration information at least includes a task pool threshold; Initialize the task pool and the asynchronous thread pool according to the initialization configuration information; The delivering the target asynchronous task to the task pool includes: Determine whether the usage in the task pool is less than the task pool threshold; If it is not less than, the target asynchronous task is blocked by timeout; When the number of tasks in the task pool is less than or equal to the task pool threshold, delivering the target asynchronous task of timeout blocking processing to the task pool; After executing the target asynchronous task in the task pool by the target asynchronous thread in the asynchronous thread pool, the method further includes: Check whether there is an asynchronous task that is currently blocked by timeout; If it exists, the asynchronous task with the longest timeout blocking processing time is delivered to the task pool, and the asynchronous task is determined according to the asynchronous task type, task amount or historical task type.
2. The method according to claim 1, characterized in that: Before receiving the target asynchronous request, the method further includes: The programming language type of the system framework is obtained, and an asynchronous interface set is generated based on the programming language type.
3. The method according to claim 1, characterized in that: The executing the target asynchronous task in the task pool by the target asynchronous thread in the asynchronous thread pool includes: Determine the running status of all asynchronous threads in the asynchronous thread pool; Taking an asynchronous thread in an idle state in the asynchronous thread pool as a target asynchronous thread; The target asynchronous task is taken out from the task pool through the target asynchronous thread, and the target asynchronous task is executed.
4. The method according to claim 3, characterized in that: The executing the target asynchronous task comprises: Parsing the target asynchronous task through the target asynchronous thread to determine the target service, and loading the target service; Obtain the loading result, and execute the callback function according to the loading result.
5. An asynchronous calling device, characterized in that: include: A receiving module is used to receive a target asynchronous request and determine a target asynchronous interface corresponding to the target asynchronous request; wherein the target asynchronous interface corresponds to target services of at least two programming languages, the target asynchronous request includes a target programming language type, a plurality of the target asynchronous interfaces form an asynchronous interface set, the target asynchronous request is parsed to determine the target programming language type; and a corresponding target asynchronous interface is searched in the asynchronous interface set based on the target programming language type; A generating module, used for generating a target asynchronous task corresponding to the target asynchronous request through the target asynchronous interface, and delivering the target asynchronous task to a task pool; An execution module is used to execute the target asynchronous task in the task pool through the target asynchronous thread in the asynchronous thread pool; wherein, the target asynchronous thread calls the target service when executing the target asynchronous task, and encapsulates the request body and callback function of the target asynchronous request into the corresponding target asynchronous task through the target asynchronous interface; wherein, the callback function at least includes a success callback function and a failure callback function, and the request body includes the service type that the asynchronous request needs to call; detect whether the task pool and the asynchronous thread pool are initialized; if the task pool and the asynchronous thread pool are not initialized, obtain initialization configuration information; wherein, the initialization configuration information The information at least includes a task pool threshold; the task pool and the asynchronous thread pool are initialized according to the initialization configuration information; it is determined whether the usage in the task pool is less than the task pool threshold; if not, the target asynchronous task is timed out and blocked; when the number of tasks in the task pool is less than or equal to the task pool threshold, the target asynchronous task that is timed out and blocked is delivered to the task pool; it is detected whether there is an asynchronous task that is timed out and blocked at present; if so, the asynchronous task with the longest timed out and blocked processing time is delivered to the task pool, and the asynchronous task is determined according to the asynchronous task type, the task amount or the historical task type.
6. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps as claimed in any one of claims 1 to 4.
7. An electronic device, characterized in that: include: A memory and a processor; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 4.
Citation Information
Patent Citations
Asynchronous task processing method and system
CN106293922A
Data transmission method based on interface asynchronous call, server and storage medium
CN109309712A
Asynchronous task scheduling method and device, computer equipment and storage medium
CN110515710A