Thread distribution method and device, electronic equipment and computer medium
By obtaining the application programming interface call information of the applet, determining the target thread and creating a mapping relationship table, the problem of slow startup speed of the applet is solved and a faster startup process is achieved.
Patent Information
- Application Number
- CN202410141233.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-31
- Publication Date
- 2025-08-01
AI Technical Summary
Frequent thread switching during the startup of the applet leads to a slow startup speed.
By obtaining the call information of the application programming interface of the target program object, determining its corresponding target thread, and creating a mapping relationship table, allocating execution threads to the application programming interface based on this table to avoid frequent thread switching.
It improves the startup speed of the applet, reduces the time consumption caused by thread switching, and improves task processing efficiency.
Smart Images

Figure CN120407046A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the technical field of program development, and particularly relates to a thread allocation method, apparatus, electronic device, and computer medium. Background Art
[0002] A mini-program is an application that can be used without being downloaded and installed. The application programming interfaces (APIs) in the mini-program framework are a series of interfaces provided for developers to implement various functions and interactions of the mini-program. In related technologies, the process of API call usually involves at least multiple thread switches to select a suitable thread for execution. During the startup process of a mini-program, multiple API calls are required, which may consume a long time due to multiple thread switches during the startup of the mini-program, resulting in a slow startup speed of the mini-program. Summary of the Invention
[0003] Embodiments of the present disclosure provide an implementation different from related technologies to solve the technical problem that frequent thread switches in related technologies result in a slow startup speed of the mini-program.
[0004] In a first aspect, the present disclosure provides a thread allocation method, including:
[0005] Obtaining call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object;
[0006] Determining a target thread corresponding to the target application programming interface from multiple preset threads according to the call information, to obtain multiple target threads corresponding to the multiple application programming interfaces;
[0007] Creating a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces;
[0008] In response to receiving an instruction to start the target program object, based on the mapping relationship table, allocating corresponding execution threads to each application programming interface in the multiple application programming interfaces.
[0009] In a second aspect, the present disclosure provides a thread allocation apparatus, including:
[0010] An obtaining unit, configured to obtain call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object;
[0011] A determination unit, configured to determine, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads, so as to obtain multiple target threads corresponding to the multiple application programming interfaces;
[0012] A creation unit, configured to create a mapping relation table, where the mapping relation table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces;
[0013] An allocation unit, configured to, in response to receiving an instruction for starting the target program object, allocate corresponding execution threads to each of the multiple application programming interfaces based on the mapping relation table.
[0014] In a third aspect, the present disclosure provides an electronic device, including:
[0015] A processor; and
[0016] A memory, configured to store executable instructions of the processor;
[0017] Wherein, the processor is configured to execute any method in the first aspect and each possible implementation manner of the first aspect by executing the executable instructions.
[0018] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any method in the first aspect and each possible implementation manner of the first aspect is implemented.
[0019] The present disclosure provides a method for obtaining call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object; determining a target thread corresponding to the target application programming interface from multiple preset threads according to the call information, to obtain multiple target threads corresponding to the multiple application programming interfaces; creating a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces; in response to receiving an instruction to start the target program object, based on the mapping relationship table, a solution for allocating corresponding execution threads to each application programming interface among the multiple application programming interfaces can analyze the data information generated when starting the target program object within a historical time period, so as to bind a corresponding target thread to each application programming interface to obtain a mapping relationship table; when the target program object is started subsequently, by querying the mapping relationship table, directly allocate corresponding target threads to the multiple application programming interfaces, avoiding frequent thread switching during the call of the application programming interface, saving time, and thus improving the startup speed of the target program object. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, the following drawings are some embodiments of the present disclosure. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. In the drawings:
[0021] Figure 1 is an architecture diagram of a small program framework provided by an exemplary embodiment of the present disclosure;
[0022] Figure 2 is a flowchart of thread allocation provided by an exemplary embodiment of the present disclosure;
[0023] Figure 3 is a flowchart of starting a target program object provided by an exemplary embodiment of the present disclosure;
[0024] Figure 4 is a structural diagram of a thread allocation device provided by an exemplary embodiment of the present disclosure;
[0025] Figure 5 is a schematic block diagram of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0026] Embodiments of the present disclosure will be described in detail below, and examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0027] In the description of the specification, claims, and drawings of the embodiments of the present disclosure, terms such as "first" and "second" are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0028] First, some terms in the embodiments of the present disclosure will be explained below to facilitate the understanding of those skilled in the art.
[0029] A Software Development Kit (SDK) is a collection of software tools, code libraries, documentation, and APIs (Application Programming Interfaces) that helps developers create applications on a specific platform or system and comprehensively improve the program in many aspects.
[0030] A User Interface (UI) refers to the overall design of the human-computer interaction, operation logic, and interface aesthetics of software.
[0031] A mini-program is an application that can be used without being downloaded and installed. The Application Programming Interfaces (APIs) in the mini-program framework are a series of interfaces provided for developers to implement various functions and interactions of the mini-program.
[0032] Figure 1 The architecture diagram of a mini-program framework provided for an exemplary embodiment of the present disclosure is as Figure 1 , the client can include traditional native applications or mini-programs built using the mini-program framework. The mini-program framework mainly includes: a logic layer (JavaScriptCore) and a view layer (WebView). The mini-program provides a data transmission and event system between the view layer and the logic layer. Information such as the structure and style of the pages of the mini-program is passed from the logic layer to the view layer, and then the view layer is responsible for rendering the pages to the user interface.
[0033] The logic layer can be used to handle tasks such as user interaction, business logic, and data processing. The JS thread is the thread on which the logic layer runs. It is independent of the main thread and is responsible for handling operations such as logic code, data calculation, network requests, as well as parsing and executing JavaScript code in the applet, and handling tasks such as page rendering and layout calculation.
[0034] The view layer can be used to handle page rendering and display, including the layout, styles, and rendering of interface elements. The main thread is the thread on which the view layer runs. It is the core thread in the applet framework and is responsible for handling tasks such as user interface rendering, event response, and logic processing. The main thread can be used to execute the business logic code of the applet, including page lifecycle functions, event callbacks, etc.; the main thread is also responsible for communication and coordination with other threads; and for executing the JavaScript code in the logic layer to handle tasks such as user input, network requests, and business logic.
[0035] In addition, multiple child threads can be created in the applet framework to execute some independent and time-consuming tasks, and these child threads can execute multiple tasks concurrently.
[0036] In related technologies, the tasks of application programming interface calls are dispatched in the logic layer of the applet. First, they will be dispatched to the main thread or a certain child thread for execution. After the application programming interface call is completed, it is necessary to return to the logic layer to call back the front end. That is to say, one application programming interface call includes at least 2 thread switches. And during the startup process of the applet, multiple application programming interface calls are required. This makes the startup of the applet consume a relatively long time due to multiple thread switches, resulting in a slower startup speed of the applet. Therefore, the present disclosure provides a thread allocation method, device, electronic device, and computer medium to solve the technical problem of the slow startup speed of the applet caused by frequent thread switches in related technologies.
[0037] The following will detail the technical solution of the present disclosure and how the technical solution of the present disclosure solves the above technical problem with specific embodiments. These specific embodiments below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present disclosure will be described below with reference to the accompanying drawings.
[0038] Figure 2 FIG. is a schematic flowchart of a thread allocation provided for an exemplary embodiment of the present disclosure. This method can be applied to terminal devices such as mobile phones, tablet computers, and personal computers. This method at least includes the following steps S1 - S4:
[0039] S1. Obtain the call information of the target application programming interface corresponding to the target program object. The target application programming interface is any one of multiple application programming interfaces called to start the target program object, and the call information is the data information generated during starting the target program object within a preset historical time period.
[0040] In some embodiments, the target program object may be a mini-program. During the startup process of the mini-program, a series of operations may need to be performed. The target application programming interface refers to any one of the multiple application programming interfaces called during these operations.
[0041] In some embodiments, the call information includes: the first average duration consumed for calling the target application programming interface, the second average duration consumed for thread switching during the process of calling the target application programming interface, the operation identification information used to indicate whether the user interface needs to be operated when calling the target application programming interface, and the number of times the target application programming interface is called during the process of starting the target program object, etc.
[0042] In some embodiments, within the preset historical time period, there may be multiple startups of the target program object. It is possible to record the first duration consumed for calling the target application programming interface and the second duration consumed for thread switching during the process of calling the target application programming interface each time the target program object is started, so as to obtain multiple first durations and multiple second durations recorded for multiple startups of the target program object; then calculate the average value of the multiple first durations and use this average value as the first average duration, and calculate the average value of the multiple second durations and use this average value as the second average duration.
[0043] Among them, the first duration consumed for calling the target application programming interface refers to the duration from initiating the call request to the target application programming interface to receiving the corresponding result; the second duration consumed for thread switching during the process of calling the target application programming interface refers to the duration from the JS thread dispatching the task (calling the target application programming interface) to returning the corresponding result to the JS thread after the task is completed during the process of calling the target application programming interface.
[0044] S2. Determine the target thread corresponding to the target application programming interface from multiple preset threads according to the call information, and obtain multiple target threads corresponding to the multiple application programming interfaces.
[0045] In some embodiments, among the multiple preset threads, there are a JS thread corresponding to the target program object, a main thread, and an application programming interface execution thread; wherein, the number of the main threads can be two, the application programming interface execution thread is the thread where the application programming interface is called, and both the JS thread and the application programming interface execution thread are child threads.
[0046] In some alternative embodiments provided by the present disclosure, in S2, determining the target thread corresponding to the target application programming interface from multiple preset threads according to the call information includes S21 - S23:
[0047] S21. When the absolute value of the difference between the first average duration and the second average duration included in the call information is greater than a first preset threshold, compare the first average duration and the second average duration;
[0048] S22. If the first average duration is less than the second average duration, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface;
[0049] In some embodiments, that the first average duration is less than the second average duration may indicate that the time consumed in the process of calling the target application programming interface is less, so the JS thread can be directly used to call the target application programming interface without dispatching the target application programming interface call task to the main thread or other child threads to save thread switching time.
[0050] S23. And / or, if the first average duration is greater than the second average duration, determine the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
[0051] In some embodiments, that the first average duration is greater than the second average duration may indicate that the time consumed by thread switching is less, so the JS thread can be used to dispatch the task of calling the target application programming interface to the main thread or a certain child thread for execution.
[0052] In some alternative embodiments provided by the present disclosure, in S23, determining the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information includes S231 - S232:
[0053] S231. If the operation identification information indicates that the user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface;
[0054] S232, and / or, if the operation identification information indicates that no user interface operation is required when calling the target application programming interface, then the application programming interface execution thread is determined to be the target thread corresponding to the target application programming interface.
[0055] Since the main thread can be responsible for handling the rendering and interaction of the user interface, during the process of calling the target application programming interface, if the user interface needs to be operated, the main thread can be determined as the target thread corresponding to the target application programming interface to ensure the normal response and update of the user interface.
[0056] If the target API call does not require user interface manipulation, a separate child thread is designated as the target thread for the target API. This means that if a task does not involve user interface manipulation, it can be executed in a separate child thread without affecting the main thread, improving task processing efficiency.
[0057] In some optional embodiments provided by the present disclosure, in S2, determining a target thread corresponding to the target application programming interface from a plurality of preset threads according to the call information includes S24-S26:
[0058] S24: If the absolute value of the difference between the first average duration and the second average duration included in the call information is not greater than a first preset threshold, determine whether the number of times included in the call information is greater than a second preset threshold;
[0059] If the absolute value of the difference between the first average duration and the second average duration is not greater than the first preset threshold, it can be considered that the time consumed by calling the target application programming interface and the time consumed by thread switching during the target application programming interface call are close. In this case, threads can be allocated based on the number of times the target application programming interface is called during the process of starting the target program object.
[0060] S25. If the number of times is greater than the second preset threshold, determining the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface;
[0061] If the number of times the target application programming interface is called during the process of starting the target program object is greater than the second preset threshold, it can be considered that the target application programming interface needs to be called frequently during the process of starting the target program object. Therefore, the JS thread can be directly used to call the target application programming interface to eliminate the subsequent thread switching process, avoid the frequent switching of threads caused by frequent calls to the target application programming interface, effectively save the initialization time of the target program object, and improve the startup speed.
[0062] S26. If the number is not greater than the second preset threshold, based on the operation identification information included in the call information, determine the target thread corresponding to the target application programming interface from multiple preset threads.
[0063] In some optional embodiments provided by the present disclosure, in S26, based on the operation identification information included in the call information, determining the target thread corresponding to the target application programming interface from multiple preset threads includes S261 - S262:
[0064] S261. If the operation identification information indicates that the user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface;
[0065] S262. And / or, if the operation identification information indicates that the user interface does not need to be operated when calling the target application programming interface, determine the application programming interface execution thread as the target thread corresponding to the target application programming interface.
[0066] Since the main thread can be responsible for processing the rendering and interaction of the user interface, during the process of calling the target application programming interface, if the user interface needs to be operated, the main thread can be determined as the target thread corresponding to the target application programming interface to ensure the normal response and update of the user interface.
[0067] During the process of calling the target application programming interface, if the user interface does not need to be operated, the application programming interface execution thread needs to be used as the target thread corresponding to the target application programming interface. The application programming interface execution thread is an independent sub - thread. That is to say, if a task does not involve the operation of the user interface, it can be selected to be executed in an independent sub - thread without affecting the work of the main thread, which can improve the task processing efficiency.
[0068] Among them, the above - mentioned first preset threshold and second preset threshold can be flexibly set by relevant developers. For example, the second preset threshold can be set to 10.
[0069] S3. Create a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and multiple target threads corresponding to the multiple application programming interfaces;
[0070] In some embodiments, the multiple identifiers of the multiple application programming interfaces and the multiple target threads correspond one by one.
[0071] S4. In response to receiving an instruction to start the target program object, based on the mapping relationship table, allocate corresponding execution threads to each application programming interface among the multiple application programming interfaces.
[0072] In some embodiments, a start control corresponding to the target program object may be displayed on a relevant page of the terminal device. The start control may include an identifier, an icon, etc. of the target program object. When it is detected that the user triggers the start control, it is determined that an instruction to start the target program object has been received.
[0073] In some optional embodiments provided by the present disclosure, in S4, based on the mapping relationship table, allocating corresponding execution threads to each application programming interface among the multiple application programming interfaces includes S41 - S42:
[0074] S41. For each application programming interface among the multiple application programming interfaces, query a target identifier identical to the to - be - queried identifier of the application programming interface from multiple identifiers in the mapping relationship table;
[0075] S42. Determine the target thread corresponding to the target identifier in the mapping relationship table as the execution thread allocated to the application programming interface, and thus allocate corresponding multiple execution threads to the multiple application programming interfaces.
[0076] In some embodiments, after S42 allocates corresponding multiple execution threads to the multiple application programming interfaces, the method further includes:
[0077] For each application programming interface among the multiple application programming interfaces, use the execution thread corresponding to the application programming interface to call the application programming interface, and thus start the target program object.
[0078] Figure 3 The flowchart of starting a target program object provided for an exemplary embodiment of the present disclosure is as Figure 3 , after the host application client of the target program object (mini - program) is started, the software development kit (SDK) of the target program object can be initialized. On the one hand, a mapping relationship table corresponding to the target program object can be created (i.e., mini - program SDK registration); on the other hand, for the application programming interfaces that need to be operated among the multiple application programming interfaces, corresponding user interface operations can be pre - executed in advance, and the operation results corresponding to the application programming interfaces are saved. The operation results may include user interface elements that have been calculated or processed, user interface states, etc., so that the corresponding interfaces can be presented faster in subsequent operations, reducing the loading time perceived by the user.
[0079] Furthermore, when an instruction for starting the target program object is received, based on the mapping relation table, execution threads are allocated to the respective application programming interfaces among the multiple application programming interfaces, and the application programming interfaces are called by using the execution threads corresponding to the respective application programming interfaces, so as to complete the startup of the target program object. Specifically, for each application programming interface, when the execution thread corresponding to the application programming interface is the main thread, the application programming interface call is executed by using the main thread, and the execution result is called back to the JS thread; when the execution thread corresponding to the application programming interface is the application programming interface execution thread, the application programming interface call is executed by using the application programming interface execution thread, and the execution result is called back to the JS thread; when the execution thread corresponding to the application programming interface is the JS thread, the application programming interface call is directly executed by using the JS thread, and the execution result is generated.
[0080] In the above solution, the thread allocation is directly performed by using the preset relation table, and the multiple application programming interfaces are allocated to different threads, thereby reducing the time consumption caused by thread switching, improving the task processing efficiency, quickly completing the initialization process of the target program object, and further improving the startup speed of the target program object.
[0081] In some optional embodiments provided by the present disclosure, the method further includes:
[0082] Performing, based on a preset period, obtaining call information of a target application programming interface corresponding to a target program object, and determining, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads, so as to obtain multiple target threads corresponding to the multiple application programming interfaces, and updating the mapping relation table based on the multiple target threads corresponding to the multiple application programming interfaces.
[0083] By periodically performing the obtaining of the call information, the system can dynamically adapt to the changes during the operation of the target program object, so as to dynamically adjust the association relationship between the application programming interface and the thread, adapt to different operation scenarios, help to cope with different loads and execution requirements; and reduce the frequency of thread switching by the system, thereby reducing the scheduling overhead and improving the overall performance.
[0084] The present disclosure provides a method for obtaining call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object; according to the call information, a target thread corresponding to the target application programming interface is determined from multiple preset threads, and multiple target threads corresponding to the multiple application programming interfaces are obtained; a mapping relationship table is created, and the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces; in response to receiving an instruction to start the target program object, based on the mapping relationship table, a scheme for allocating corresponding execution threads to each of the multiple application programming interfaces can analyze the data information generated when starting the target program object during a historical time period, so as to bind a corresponding target thread to each application programming interface to obtain a mapping relationship table; when the target program object is started subsequently, by querying the mapping relationship table, corresponding target threads are directly allocated to the multiple application programming interfaces, avoiding frequent thread switching during the call of the application programming interface, saving time, and thus improving the startup speed of the target program object.
[0085] Figure 4 FIG. 4 is a schematic structural diagram of a thread allocation device provided in an exemplary embodiment of the present disclosure;
[0086] Wherein, the device includes:
[0087] An obtaining unit 41, configured to obtain call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object;
[0088] A determining unit 42, configured to determine a target thread corresponding to the target application programming interface from multiple preset threads according to the call information, and obtain multiple target threads corresponding to the multiple application programming interfaces;
[0089] A creating unit 43, configured to create a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces;
[0090] An allocating unit 44, configured to, in response to receiving an instruction to start the target program object, based on the mapping relationship table, allocate corresponding execution threads to each of the multiple application programming interfaces.
[0091] In some alternative embodiments provided by the present disclosure, among the multiple preset threads, there are a JS thread corresponding to the target program object, a main thread, and an application programming interface execution thread.
[0092] In some alternative embodiments provided by the present disclosure, the call information includes: a first average duration consumed for calling the target application programming interface, a second average duration consumed for thread switching during the process of calling the target application programming interface, and an operation identification information for indicating whether it is necessary to operate the user interface when calling the target application programming interface. When the determining unit 42 is used to determine the target thread corresponding to the target application programming interface from multiple preset threads according to the call information, it is specifically used for:
[0093] When the absolute value of the difference between the first average duration and the second average duration included in the call information is greater than a first preset threshold, compare the first average duration and the second average duration;
[0094] If the first average duration is less than the second average duration, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the first average duration is greater than the second average duration, determine the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
[0095] In some alternative embodiments provided by the present disclosure, the call information further includes: the number of times of calling the target application programming interface during the process of starting the target program object. When the determining unit 42 is used to determine the target thread corresponding to the target application programming interface from multiple preset threads according to the call information, it is specifically used for:
[0096] When the absolute value of the difference between the first average duration and the second average duration included in the call information is not greater than the first preset threshold, determine whether the number included in the call information is greater than a second preset threshold;
[0097] If the number is greater than the second preset threshold, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the number is not greater than the second preset threshold, determine the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
[0098] In some alternative embodiments provided by the present disclosure, when the determining unit 42 is configured to determine the target thread corresponding to the target application programming interface from a plurality of preset threads based on the operation identification information included in the call information, it is specifically configured to:
[0099] If the operation identification information indicates that the user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface; and / or if the operation identification information indicates that the user interface does not need to be operated when calling the target application programming interface, determine the application programming interface execution thread as the target thread corresponding to the target application programming interface.
[0100] In some alternative embodiments provided by the present disclosure, when the allocation unit 44 is configured to allocate corresponding execution threads to each of the plurality of application programming interfaces based on the mapping relation table, it is specifically configured to:
[0101] For each of the plurality of application programming interfaces, query the target identifier in the plurality of identifiers in the mapping relation table that is the same as the identifier to be queried of the application programming interface;
[0102] Determine the target thread corresponding to the target identifier in the mapping relation table as the execution thread allocated to the application programming interface, and thus allocate corresponding multiple execution threads to the plurality of application programming interfaces.
[0103] In some alternative embodiments provided by the present disclosure, the device is further configured to:
[0104] Execute the step of obtaining the call information of the target application programming interface corresponding to the target program object based on a preset period, and determining the target thread corresponding to the target application programming interface from a plurality of preset threads according to the call information to obtain a plurality of target threads corresponding to the plurality of application programming interfaces, and update the mapping relation table based on the plurality of target threads corresponding to the plurality of application programming interfaces.
[0105] It should be understood that the device embodiments and the method embodiments can correspond to each other, and similar descriptions can refer to the method embodiments. To avoid repetition, it will not be elaborated here. Specifically, the device can execute the above method embodiments, and the foregoing and other operations and / or functions of each module in the device respectively correspond to the corresponding processes in each method in the above method embodiments. For the sake of brevity, it will not be elaborated here.
[0106] In the foregoing, the apparatus according to the embodiments of the present disclosure has been described from the perspective of functional modules. It should be understood that the functional modules may be implemented in the form of hardware, or in the form of instructions in software, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in the present disclosure may be completed by the integrated logic circuit in the hardware in the processor and / or the instructions in the form of software. The steps of the method disclosed in combination with the embodiments of the present disclosure may be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. Optionally, the software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps in the foregoing method embodiments.
[0107] Figure 5 FIG. is a schematic block diagram of an electronic device provided by an embodiment of the present disclosure. The electronic device may include:
[0108] a memory 701 and a processor 702. The memory 701 is used to store a computer program and transmit the program code to the processor 702. In other words, the processor 702 may call and run the computer program from the memory 701 to implement the method in the embodiments of the present disclosure.
[0109] For example, the processor 702 may be used to execute the foregoing method embodiments according to the instructions in the computer program.
[0110] In some embodiments of the present disclosure, the processor 702 may include, but is not limited to:
[0111] a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like.
[0112] In some embodiments of the present disclosure, the memory 701 includes, but is not limited to:
[0113] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory can be Read-Only Memory (ROM), Programmable ROM (PROM), Erasable PROM (EPROM), Electrically Erasable PROM (EEPROM), or flash memory. The volatile memory can be Random Access Memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Synch Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0114] In some embodiments of the present disclosure, the computer program may be divided into one or more modules, which are stored in the memory 701 and executed by the processor 702 to complete the method provided by the present disclosure. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.
[0115] As Figure 5 shown, the electronic device may further include:
[0116] A transceiver 703, which can be connected to the processor 702 or the memory 701.
[0117] Among them, the processor 702 can control the transceiver 703 to communicate with other devices. Specifically, it can send information or data to other devices, or receive information or data sent by other devices. The transceiver 703 can include a transmitter and a receiver. The transceiver 703 may further include an antenna, and the number of antennas can be one or more.
[0118] It should be understood that each component in the electronic device is connected through a bus system. Among them, the bus system includes not only a data bus, but also a power bus, a control bus, and a status signal bus.
[0119] The present disclosure also provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a computer, the computer can execute the methods in the above method embodiments. Or rather, the embodiments of the present disclosure also provide a computer program product containing instructions. When the instructions are executed by a computer, the computer executes the methods in the above method embodiments.
[0120] When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present disclosure are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from a website, a computer, a server, or a data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that integrates one or more available media. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital video disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)).
[0121] According to one or more embodiments of the present disclosure, a thread allocation method is provided, including:
[0122] Obtain the call information of the target application programming interface corresponding to the target program object, where the target application programming interface is any one of the multiple application programming interfaces called to start the target program object;
[0123] According to the call information, determine the target thread corresponding to the target application programming interface from multiple preset threads, and obtain multiple target threads corresponding to the multiple application programming interfaces;
[0124] Create a mapping table, where the mapping table includes multiple identifiers of the multiple application programming interfaces and multiple target threads corresponding to the multiple application programming interfaces;
[0125] In response to receiving an instruction to start the target program object, based on the mapping table, allocate corresponding execution threads to each of the multiple application programming interfaces among the multiple application programming interfaces.
[0126] According to one or more embodiments of the present disclosure, the multiple preset threads include a JS thread, a main thread, and an application programming interface execution thread corresponding to the target program object.
[0127] According to one or more embodiments of the present disclosure, the call information includes: a first average duration consumed for calling the target application programming interface, a second average duration consumed for thread switching during the process of calling the target application programming interface, and an operation identification information for indicating whether it is necessary to operate the user interface when calling the target application programming interface. Determining the target thread corresponding to the target application programming interface from multiple preset threads according to the call information includes:
[0128] When the absolute value of the difference between the first average duration and the second average duration included in the call information is greater than a first preset threshold, compare the first average duration and the second average duration;
[0129] If the first average duration is less than the second average duration, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the first average duration is greater than the second average duration, determine the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
[0130] According to one or more embodiments of the present disclosure, the call information further includes: the number of times of calling the target application programming interface during the process of starting the target program object. Determining the target thread corresponding to the target application programming interface from multiple preset threads according to the call information includes:
[0131] When the absolute value of the difference between the first average duration and the second average duration included in the call information is not greater than the first preset threshold, determine whether the number included in the call information is greater than a second preset threshold;
[0132] If the number of times is greater than the second preset threshold, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the number of times is not greater than the second preset threshold, determine the target thread corresponding to the target application programming interface from the multiple preset threads based on the operation identification information included in the call information.
[0133] According to one or more embodiments of the present disclosure, the determining the target thread corresponding to the target application programming interface from the multiple preset threads based on the operation identification information included in the call information includes:
[0134] If the operation identification information indicates that the user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface; and / or if the operation identification information indicates that the user interface does not need to be operated when calling the target application programming interface, determine the application programming interface execution thread as the target thread corresponding to the target application programming interface.
[0135] According to one or more embodiments of the present disclosure, allocating corresponding execution threads to each application programming interface among the multiple application programming interfaces based on the mapping relationship table includes:
[0136] For each application programming interface among the multiple application programming interfaces, query the target identifier in the multiple identifiers in the mapping relationship table that is the same as the identifier to be queried of the application programming interface;
[0137] Determine the target thread corresponding to the target identifier in the mapping relationship table as the execution thread allocated to the application programming interface, and further allocate multiple corresponding execution threads to the multiple application programming interfaces.
[0138] According to one or more embodiments of the present disclosure, the method further includes:
[0139] Execute the step of obtaining the call information of the target application programming interface corresponding to the target program object based on a preset period, and determine the target thread corresponding to the target application programming interface from the multiple preset threads according to the call information, to obtain multiple target threads corresponding to the multiple application programming interfaces, and update the mapping relationship table based on the multiple target threads corresponding to the multiple application programming interfaces.
[0140] According to one or more embodiments of the present disclosure, there is provided a thread allocation device, including:
[0141] An acquisition unit, configured to acquire call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object;
[0142] A determination unit, configured to determine, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads, so as to obtain multiple target threads corresponding to the multiple application programming interfaces;
[0143] A creation unit, configured to create a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces;
[0144] An allocation unit, configured to, in response to receiving an instruction to start the target program object, based on the mapping relationship table, allocate corresponding execution threads to each of the multiple application programming interfaces.
[0145] According to one or more embodiments of the present disclosure, the multiple preset threads include a JS thread, a main thread, and an application programming interface execution thread corresponding to the target program object.
[0146] According to one or more embodiments of the present disclosure, the call information includes: a first average duration consumed for calling the target application programming interface, a second average duration consumed for thread switching during the process of calling the target application programming interface, and operation identification information for indicating whether a user interface needs to be operated when calling the target application programming interface. When the determination unit is configured to determine, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads, it is specifically configured to:
[0147] When the absolute value of the difference between the first average duration and the second average duration included in the call information is greater than a first preset threshold, compare the first average duration and the second average duration;
[0148] If the first average duration is less than the second average duration, determine the JS thread in the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the first average duration is greater than the second average duration, based on the operation identification information included in the call information, determine the target thread corresponding to the target application programming interface from the multiple preset threads.
[0149] According to one or more embodiments of the present disclosure, the call information further includes: the number of times of calling the target application programming interface during the process of starting the target program object. When the determining unit 42 is used to determine the target thread corresponding to the target application programming interface from multiple preset threads according to the call information, specifically:
[0150] When the absolute value of the difference between the first average duration and the second average duration included in the call information is not greater than a first preset threshold, determine whether the number included in the call information is greater than a second preset threshold;
[0151] If the number is greater than the second preset threshold, determine the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the number is not greater than the second preset threshold, determine the target thread corresponding to the target application programming interface from the multiple preset threads based on the operation identification information included in the call information.
[0152] According to one or more embodiments of the present disclosure, when the determining unit 42 is used to determine the target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information, specifically:
[0153] If the operation identification information indicates that the user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface; and / or if the operation identification information indicates that the user interface does not need to be operated when calling the target application programming interface, determine the application programming interface execution thread as the target thread corresponding to the target application programming interface.
[0154] According to one or more embodiments of the present disclosure, when the allocation unit is used to allocate corresponding execution threads to each application programming interface among the multiple application programming interfaces based on the mapping relationship table, specifically:
[0155] For each application programming interface among the multiple application programming interfaces, query the target identifier in the multiple identifiers in the mapping relationship table that is the same as the to-be-query identifier of the application programming interface;
[0156] Determine the target thread corresponding to the target identifier in the mapping relationship table as the execution thread allocated to the application programming interface, and further allocate corresponding multiple execution threads to the multiple application programming interfaces.
[0157] According to one or more embodiments of the present disclosure, the device is further configured to:
[0158] Execute the step of obtaining the call information of the target application programming interface corresponding to the target program object based on a preset period, and determine the target thread corresponding to the target application programming interface from multiple preset threads according to the call information, so as to obtain multiple target threads corresponding to multiple application programming interfaces, and update the mapping relationship table based on the multiple target threads corresponding to multiple application programming interfaces.
[0159] According to one or more embodiments of the present disclosure, there is provided an electronic device, including:
[0160] A processor; and
[0161] A memory for storing executable instructions of the processor;
[0162] Wherein, the processor is configured to execute the above-mentioned thread allocation method by executing the executable instructions.
[0163] According to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the above-mentioned thread allocation method.
[0164] Those of ordinary skill in the art can realize that the modules and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present disclosure.
[0165] In several embodiments provided by the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces, and the indirect coupling or communication connection of the device or module can be in an electrical, mechanical or other form.
[0166] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network elements. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. For example, in various embodiments of the present disclosure, each functional module can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.
[0167] The above are only specific embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present disclosure can easily think of changes or substitutions, which should be covered by the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A thread allocation method, characterized in that, Including: Obtaining call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object; Determining a target thread corresponding to the target application programming interface from multiple preset threads according to the call information, and obtaining multiple target threads corresponding to the multiple application programming interfaces; Creating a mapping relationship table, where the mapping relationship table includes multiple identifiers of the multiple application programming interfaces and the multiple target threads corresponding to the multiple application programming interfaces; In response to receiving an instruction to start the target program object, based on the mapping relationship table, allocating corresponding execution threads to each application programming interface among the multiple application programming interfaces.
2. The method according to claim 1, wherein The multiple preset threads include a JS thread, a main thread, and an application programming interface execution thread corresponding to the target program object.
3. The method according to claim 2, characterized in that, The call information includes: a first average duration consumed for calling the target application programming interface, a second average duration consumed for thread switching during the process of calling the target application programming interface, and operation identification information for indicating whether a user interface needs to be operated when calling the target application programming interface. The determining a target thread corresponding to the target application programming interface from multiple preset threads according to the call information includes: When the absolute value of the difference between the first average duration and the second average duration included in the call information is greater than a first preset threshold, comparing the first average duration and the second average duration; If the first average duration is less than the second average duration, determining the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the first average duration is greater than the second average duration, determining a target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
4. The method according to claim 3, wherein The call information further includes: the number of times the target application programming interface is called during the process of starting the target program object. The determining a target thread corresponding to the target application programming interface from multiple preset threads according to the call information includes: When the absolute value of the difference between the first average duration and the second average duration included in the call information is not greater than the first preset threshold, determining whether the number included in the call information is greater than a second preset threshold; If the number is greater than the second preset threshold, determining the JS thread among the multiple preset threads as the target thread corresponding to the target application programming interface; and / or if the number is not greater than the second preset threshold, determining a target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information.
5. The method according to claim 3 or 4, characterized in that The determining a target thread corresponding to the target application programming interface from multiple preset threads based on the operation identification information included in the call information includes: If the operation identification information indicates that a user interface needs to be operated when calling the target application programming interface, determine the main thread as the target thread corresponding to the target application programming interface; and / or if the operation identification information indicates that a user interface does not need to be operated when calling the target application programming interface, determine the application programming interface execution thread as the target thread corresponding to the target application programming interface.
6. The method according to claim 1, wherein Based on the mapping relation table, allocating corresponding execution threads for each of the multiple application programming interfaces includes: For each of the multiple application programming interfaces, query a target identifier from the multiple identifiers in the mapping relation table that is the same as the identifier to be queried of the application programming interface; Determine the target thread corresponding to the target identifier in the mapping relation table as the execution thread allocated to the application programming interface, thereby allocating multiple corresponding execution threads for the multiple application programming interfaces.
7. The method according to claim 1, characterized in that The method further includes: Performing, based on a preset period, the step of obtaining call information of a target application programming interface corresponding to a target program object, and determining, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads to obtain multiple target threads corresponding to the multiple application programming interfaces, and updating the mapping relation table based on the multiple target threads corresponding to the multiple application programming interfaces.
8. A thread allocation device, characterized in that, Includes: An obtaining unit, configured to obtain call information of a target application programming interface corresponding to a target program object, where the target application programming interface is any one of multiple application programming interfaces called to start the target program object; A determining unit, configured to determine, according to the call information, a target thread corresponding to the target application programming interface from multiple preset threads to obtain multiple target threads corresponding to the multiple application programming interfaces; A creating unit, configured to create a mapping relation table, where the mapping relation table includes multiple identifiers of the multiple application programming interfaces and multiple target threads corresponding to the multiple application programming interfaces; An allocating unit, configured to, in response to receiving an instruction for starting the target program object, allocate corresponding execution threads for each of the multiple application programming interfaces based on the mapping relation table.
9. An electronic device, characterized in that, Includes: A processor; And A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the method according to any one of claims 1-7 by executing the executable instructions.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer program, when executed by a processor, implements the method according to any one of claims 1-7.