Application program running method and electronic equipment
By improving the priority of lock-holding threads and kernel-level resource scheduling, it solves the problem of slow startup and slow loading of smartphone applications, significantly reduces page freezes and frame drops, and improves user experience.
Patent Information
- Application Number
- CN202410613001.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-10
- Publication Date
- 2024-08-30
AI Technical Summary
Applications on smartphones are slow to start and load, resulting in page freezes and frame drops, especially when small programs in the application are started or when scanning code results are loaded.
By increasing the priority of the lock-holding thread in the application and prioritizing resource scheduling at the kernel level, we ensure that the lock-holding thread can frequently obtain CPU time slices and shorten the running time of the lock-holding thread, thereby reducing the length of time the first thread is blocked. Avoid page freezes and slow loading problems.
It effectively improves the startup speed and loading speed of applications, reduces page freezes and frame drops, and improves user experience.
Smart Images

Figure CN118567744A
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 202211403614.5 submitted to the China Patent Office, application date November 10, 2022, and invention name “Method for running application and electronic device”. Technical Field
[0002] The present application relates to the field of terminals, and in particular to a method for running an application and an electronic device. Background Art
[0003] With the continuous development of smart phones, more and more applications are running on smart phones, such as video applications, social applications, etc. In order to reduce the cost of using applications for users, some applications also allow other small programs to run in the application.
[0004] However, when the application is started, there will be problems with slow startup and startup page jamming; the mini-programs in the application will also have problems with slow startup or slow loading when starting or loading scan results (such as the results of scanning a QR code). Summary of the invention
[0005] In order to solve the above technical problems, the present application provides a method for running an application and an electronic device, which can improve the speed of starting up the electronic device or loading data, and avoid freezes and frame drops in the display page of the application.
[0006] In a first aspect, the present application provides a method for running an application, comprising: in response to a user's operation on the application, a first thread in the application runs; if the first thread fails to lock a target resource and it is detected that the first thread belongs to the target thread, the target thread updates the first priority of the second thread to a second priority, the second priority is higher than the first priority, and the second thread is the thread holding the lock of the target resource; the priority of the target thread is higher than the first priority, and the first identification information of the second thread is transmitted to the kernel; the kernel schedules resources for the second thread preferentially within a preset time length based on the first identification information; if the second thread does not release the lock within the preset time length, it runs according to the second priority.
[0007] In this way, the electronic device can be a mobile phone, a bracelet, a tablet computer, a computer and other devices. When the user operates the application, the first thread in the application runs. The user's operation on the application can be an operation to start the application, an operation to start the applet in the application, an operation to scan a QR code, etc. After the first thread is started, when the first thread fails to lock the target resource and detects that the first thread is the target thread, the priority of the locking thread (i.e., the second thread) is increased; and the first identification information of the locking thread is transmitted to the kernel, and the kernel prioritizes scheduling resources for the locking thread within a preset duration. Since the kernel prioritizes scheduling resources for the second thread, the second thread can obtain the CPU time slice first, that is, the second thread can frequently obtain the CPU time slice within the preset duration, thereby improving the running speed of the second thread and shortening the running time of the second thread. At the same time, the kernel only allocates resources to the second thread preferentially within the preset time. When the second thread does not release the lock within the preset time, the second thread runs according to the second priority. Since the second priority of the second thread is higher than the first priority, the processor can allocate resources to the second thread according to the second priority, avoiding the problem that the second thread is in a ready state and cannot release the lock in time after other threads with higher priority than the first priority occupy the CPU after exceeding the preset time. In this example, the method of modifying the priority of the second thread and the method of allocating resources to the second thread by the kernel within the preset time are combined. The two methods complement each other, which can further speed up the running speed of the second thread and reduce the length of time the first thread is blocked, thereby solving the problems of slow data loading, frame loss and freeze on the startup page caused by the blocking of the first thread.
[0008] According to the first aspect, the method further includes: the first thread performs a locking operation on the target resource, and if it is detected that the lock of the target resource is heavily locked and the lock has not been released by the second thread, the first thread determines that the locking of the target resource has failed. In this way, if the lock of the target resource is in a lightly locked state, the first thread can try to lock it multiple times, and the first thread will not enter a blocked state; and if the lock is heavily locked and has not been released by the second thread, the first thread will enter a blocked state after the locking fails. In this case, detecting whether the first thread belongs to the target thread can avoid the situation where the priority of the second thread is changed incorrectly.
[0009] According to the first aspect, detecting whether the first thread belongs to the target thread includes: the first thread detecting whether the process to which the first thread belongs is in the foreground running state; if the first thread determines that the process to which the first thread belongs is in the foreground running state, then detecting whether the first thread is a key thread; if the first thread detects that the first thread is a key thread, then determining that the first thread belongs to the target thread. In this way, the blocking of the key thread of the process in the application usually causes page freezes and frame drops. For the blocking of the key thread in the application running in the background, it is not easy to cause abnormalities in the display screen of the application. Therefore, only the process in the foreground running state is detected, and the scenario where the priority of the second thread needs to be increased and the kernel prioritizes the scheduling of resources for the second thread can be quickly located.
[0010] According to the first aspect, detecting whether the first thread is a key thread includes: the first thread obtains the second identification information of the process to which the first thread belongs; judging whether the second identification information is the same as the third identification information of the first thread; if the second identification information is detected to be the same as the third identification information, then determining that the first thread is a key thread; if the second identification information is detected to be different from the third identification information, then determining that the first thread is not a key thread. In this way, through the identification information of the first thread and the identification information of the process to which the first thread belongs, it is possible to quickly judge whether the first thread is a key thread in the process to which it belongs.
[0011] According to the first aspect, the kernel preferentially schedules resources for the second thread within a preset duration according to the first identification information, including: if the kernel obtains the first identification information, the timer is started; when the kernel detects that the duration recorded by the timer reaches the preset duration, the operation of preferentially scheduling resources for the second thread is terminated. In this way, the duration for which the kernel preferentially schedules resources for the second thread can be detected in time through the timer, and after reaching the preset duration, the operation of preferentially scheduling resources for the second thread is terminated, which can avoid the impact of the operation of preferentially scheduling resources for the second thread for a long time on other threads.
[0012] According to the first aspect, the first identification information includes: the identity identification number of the second thread and the first attribute information, and the first attribute information is used to indicate whether the kernel prioritizes the scheduling of resources for the second thread. In this way, the kernel can quickly determine whether to prioritize the scheduling of resources for the second thread according to the first attribute information.
[0013] According to the first aspect, the method further includes: when the target thread successfully locks the target resource, the second priority of the second thread is updated to the first priority. In this way, when the second thread has released the lock, the target thread attempts to lock the target resource, and after the lock is successful, the target thread will end the blocking state and resume operation. At this time, the target thread changes the second priority of the second thread to the first priority, so that the priority of the second thread can be restored to the original first priority in time to avoid affecting the operation of other threads.
[0014] According to the first aspect, the target thread updates the first priority of the second thread to the second priority, including: the target thread detects that the lock is re-locked, then obtains the first identification information of the second thread; the target thread updates the first priority to the second priority through the interface according to the first identification information. In this way, the first thread can pass the first identification information of the second thread to the kernel by calling the interface.
[0015] According to the first aspect, the preset duration is less than or equal to 20 milliseconds. In this way, the kernel can avoid the problem of preferentially scheduling resources for the second thread for a long time and affecting the operation of other threads.
[0016] According to the first aspect, the first thread belongs to the application or to a small program in the application. In this way, the first thread can belong to the application or to a small program in the application, which increases the applicable scenarios of the method for running the application.
[0017] In a second aspect, the present application provides a method for running an application, comprising: in response to a user operation on the application, a first thread in the application runs; if the first thread in the application fails to lock a target resource and it is detected that the first thread belongs to the target thread, the target thread updates the first priority of the second thread to a second priority, the second priority is higher than the first priority, and the second thread is the thread holding the lock of the target resource; the priority of the target thread is higher than the first priority, and the second thread runs according to the second priority.
[0018] In this way, the electronic device can be a mobile phone, a bracelet, a tablet computer, a computer and other devices. When the first thread of the application fails to lock the target resource and detects that the first thread is the target thread, the priority of the lock-holding thread (i.e., the second thread) is increased; the second thread runs at the second priority, and since the second priority of the second thread is higher than the first priority, the processor can allocate resources to the second thread according to the second priority, which can reduce the probability of threads higher than the first priority seizing the CPU, thereby reducing the probability of the first thread being blocked for a long time, thereby reducing the problems of slow data loading, frame loss, and freezes on the startup page caused by the first thread being blocked for a long time.
[0019] According to the second aspect, detecting whether the first thread belongs to the target thread includes: the first thread detecting whether the process to which the first thread belongs is in the foreground running state; if the first thread determines that the process to which the first thread belongs is in the foreground running state, detecting whether the first thread is a key thread; if the first thread detects that the first thread is a key thread, determining that the first thread belongs to the target thread.
[0020] According to the second aspect, detecting whether the first thread is a critical thread includes: the first thread obtains second identification information of the process to which the first thread belongs; determining whether the second identification information is the same as the third identification information of the first thread; if it is detected that the second identification information is the same as the third identification information, determining that the first thread is the critical thread; if it is detected that the second identification information is not the same as the third identification information, determining that the first thread is not the critical thread.
[0021] According to the second aspect, the method further includes: when the target thread successfully locks the target resource, updating the second priority of the second thread to the first priority.
[0022] Any implementation of the second aspect corresponds to any implementation of the first aspect. The technical effect corresponding to any implementation of the second aspect can refer to the technical effect corresponding to any implementation of the first aspect, which will not be repeated here.
[0023] In a third aspect, the present application provides an electronic device comprising: a memory and a processor, the memory being coupled to the processor; the memory storing program instructions, which, when executed by the processor, enables the electronic device to execute a method for running an application corresponding to any one of the implementations of the first aspect, or to execute a method for running an application corresponding to any one of the implementations of the second aspect.
[0024] The third aspect and any implementation method of the third aspect respectively correspond to the first aspect and any implementation method of the first aspect, or correspond to the second aspect and any implementation method of the second aspect, and will not be repeated here.
[0025] In a fourth aspect, the present application provides a computer-readable medium for storing a computer program. When the computer program is run on an electronic device, the electronic device executes a method for running an application corresponding to any one of the implementations of the first aspect, or executes a method for running an application corresponding to any one of the implementations of the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application 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 any creative labor.
[0027] Figure 1 is a schematic diagram showing an electronic device starting a video application program;
[0028] Figure 2 It is an exemplary illustration of the duration corresponding to each running state of a key thread;
[0029] Figure 3 is an exemplary Java object header structure;
[0030] Figure 4a is a schematic diagram showing an exemplary embodiment of thread A competing for a lock of a shared resource;
[0031] Figure 4b is a schematic diagram exemplarily showing a thread calling a CPU when a startup page of an application program freezes;
[0032] Figure 5 is a schematic diagram showing the structure of an electronic device;
[0033] Figure 6 is a software structure block diagram of an electronic device exemplarily shown;
[0034] Figure 7 is a flowchart showing an exemplary operation of an application program;
[0035] Figure 8 is a schematic diagram exemplarily showing the interaction between the first thread, the second thread and the kernel;
[0036] Fig. 9 is a schematic diagram exemplarily showing a thread calling a CPU using the method for running an application program in the present application;
[0037] Fig.10 is a flowchart showing an exemplary operation of an application program;
[0038] Fig.11 It is a schematic diagram exemplarily showing the interaction between the first thread and the second thread. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0040] Before describing the technical solution of the embodiments of the present application, the application scenarios of the embodiments of the present application are first described with reference to the accompanying drawings. Figure 1 FIG. 1 is a schematic diagram showing an exemplary electronic device starting a video application (such as application A). Figure 1 As shown, in response to the user's startup operation, the display interface 101 of the mobile phone displays the startup animation of the application A. The normal screen of the startup animation is as follows Figure 1 As shown in 1a, when the startup animation is stuck or lost, the display effect in the display interface 102 is as follows Figure 1 As shown in 1b. When the user finds that the phone appears Figure 1 When the jamming problem shown in 1b is encountered, the user may mistakenly believe that the electronic device has a jamming problem, which reduces the user's experience of using the electronic device.
[0041] In another example, when a small program in a chat application is started, there is also a problem of long startup time. For applications or small programs with scanning functions, the time from the end of scanning the QR code to the display of the scan results is long, and users are easily mistaken for the problem that the application is stuck. Usually, when the user encounters an application stuck, they will manually kill the application (that is, end the entire application), but even if the application or small program is restarted, the above problems may still exist (such as the long time to display the results of the QR code), which reduces the user's experience of using the electronic device.
[0042] During the running of the application, multiple processes will be generated, each process includes multiple (such as 2 or more) threads. Multiple threads can run simultaneously. Figure 1 The performance analysis of application A in the application can be performed. For example, the running status of the thread in the stuck page can be analyzed by a performance analysis tool. Figure 2 The duration corresponding to each running state of a certain key thread is shown as an example. The key thread may be the UI (User Interface) thread of the startup page of the application A. Figure 2As shown, the total wall duration of the thread during the startup process is 234.58ms. The thread is in the ready state for 195.764151ms, the thread is in the running state for 22.721464ms, the thread is in the sleep state for 8.95877ms, and the thread is in the uninterruptible sleep state for 7.135615ms. The time the thread is in the ready state accounts for 83% of the total time, while the running time accounts for 9.6% of the total time. It can be seen that the UI thread consumes a lot of time in the ready state, resulting in the problem of the total running time of the UI thread, which makes the page display time longer, or there are problems such as freezes and frame drops.
[0043] Specifically, when an application is running, the operating system of the mobile phone creates a process for the application, which may include one or more threads. When multiple applications are running simultaneously in a mobile phone, the CPU allows the instructions and data of each program to run on the CPU for a very short period of time (time slice). When the program time slice ends, it switches to the next program. Due to the time-sharing mechanism of the CPU, when multiple threads concurrently access shared data, in order to ensure that the shared data is only used by one or some threads at the same time, it is usually implemented in a mutually exclusive synchronization manner, such as pessimistic locking (Synchronized), which is implemented through the Monitor synchronization mechanism.
[0044] Figure 3 FIG. 1 is an exemplary diagram showing the structure of the Java object header. From the object header, relevant information about the lock status of the target resource can be identified. Figure 3 As shown, the lock states include unlocked state (Unlock State), thin state (Thin State, also known as "thin lock") state and fat state (Fat State, also known as "fat lock"). In actual applications, the lock also includes other states, which are not listed one by one in this example.
[0045] When the lock in a shared resource is in an unlocked state, the shared resource can be locked by any thread and the lock of the shared resource can be acquired. Figure 3 As shown, the object header includes 32 bits, and bits 30 to 31 are used to indicate the lock type, where "00" is used to indicate that the lock is in an unlocked state or a lightly locked state. Bits 29 and 28 are respectively a mark bit and a read barrier bit, which are used to cooperate with the GC (Garbage Collection) mechanism and will not be described in detail here. When the lock is in an unlocked state, bits 0 to 27 are all 0.
[0046] Light lock state: refers to the situation that fewer threads request the lock within a period of time, and the execution time of the thread holding the lock is short, and other waiting threads can obtain the lock in a limited spin waiting period. Bits 30 to 31 of the object header structure are also used to indicate the lock type, and bits 29 and 28 are mark bit and Read Barrier bit respectively. Bits 0 to 27 include the lock count and the identity number of the thread holding the lock.
[0047] Re-locked state: When the lock in a shared resource is in a re-locked state, only one thread can hold the lock. When multiple threads access the shared resource at the same time, the non-lock holder thread will first try to obtain the ownership of the monitor in the lock object of the shared resource; if the non-lock holder thread fails to obtain the ownership of the monitor, the current non-lock holder thread will be blocked, waiting for the lock holder thread to unlock and then wake up, and compete for the lock of the shared resource again. Bits 30 to 31 of the object header structure are also used to indicate the lock type, where "01" is used to indicate that the current state is re-locked. Bits 29 and 28 are the mark bit and the read barrier bit, respectively. These two bits are used to cooperate with the GC (Garbage Collection) mechanism and will not be described in detail here. Bits 0 to 27 include the monitor object's identity number (Monitor Id).
[0048] Figure 4a FIG. 1 is a schematic diagram showing that the CPU is occupied when thread A competes for a lock of a shared resource. Figure 4a As shown, thread C accesses the shared resource at time T0 and successfully locks the shared resource, that is, thread C obtains the lock of the shared resource at time T0. If the lock is in the relocked state, when thread A competes to lock the shared resource at time T1, since the lock of the shared resource is already held by thread C and the lock is in the relocked state, thread A will be blocked and wait for thread C to release the lock of the shared resource. When thread C releases the lock of the shared resource at time T2, thread A is awakened by thread C and competes for the lock of the shared resource again. At this time, since thread C has released the lock of the shared resource, thread A successfully holds the lock. Figure 4a As shown, time T1 to T3 is the duration that thread A is in a blocked state.
[0049] In some scenarios, such as Figure 1 As shown in 1b, in the scenario where the startup page of the application is stuck, it is assumed that the UI thread is thread A. The priority of thread A is higher than the priority of thread B, and the priority of thread B is higher than the priority of thread C. The thread with a higher priority calls computing resources first.
[0050] like Figure 4b As shown in the figure, thread C locked the shared resource at time T0, and the lock is in the re-locked state. Thread A locked the shared resource at time T1. Since the lock of the target resource is already held by thread C, thread A failed to compete for the lock, causing thread A to enter a blocked state. Since thread B has a higher priority than thread C, the CPU will prioritize thread B in scheduling resources, that is, thread B will occupy the CPU before thread C. Figure 4b As shown in the figure, thread B seizes the CPU at time T2, and thread C becomes ready at time T2, waiting for thread B to run. Thread B finishes running at time T3 and releases the occupied CPU. At this time, thread C obtains the CPU and continues to run until the lock is released at time T4. After thread C releases the lock, thread A successfully competes for the lock. Since thread B has a higher priority than thread C, thread B can seize the CPU before thread C, resulting in an increase in the running time of thread C (that is, the increase is T4-T3), which increases the blocking time of thread A. In other words, Figure 4b In the scenario shown in , the priority of thread B is higher than that of the lock-holding thread, and resources are scheduled preferentially in the lock-holding thread. The total running time (including ready time and running time) of the lock-holding thread increases, and the blocking time of the UI thread increases, causing the startup page of the application to freeze and drop frames.
[0051] A method for running an application is provided in an embodiment of the present application, and the method is executed by an electronic device, and the electronic device can be a mobile phone, a bracelet, a tablet computer, a computer and other devices. When the first thread of the application fails to lock the target resource and the first thread is detected as the target thread, the priority of the lock-holding thread is increased; and the identification information of the lock-holding thread is transmitted to the kernel, and the kernel prioritizes scheduling resources for the lock-holding thread within a preset time. By giving priority to scheduling resources for the lock-holding thread by the kernel, if the lock-holding thread does not release the lock within the preset time, the lock-holding thread can run at a high priority, so that the processor can prioritize allocating resources to the lock-holding thread, further shortening the running time of the lock-holding thread, and shortening the blocking time of the first thread, so as to solve the problems of frame loss and freeze in the application, and the problem that the application takes too long to display the scan result.
[0052] Figure 5 This is a schematic diagram of the structure of an electronic device 100 shown in an embodiment of the present application. It should be understood that: Figure 5 The electronic device 100 shown is only one example of an electronic device, and the electronic device 100 may have more or fewer components than those shown in the figure, may combine two or more components, or may have a different configuration of components. Figure 1 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0053] The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
[0054] Figure 6 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0055] The layered architecture of the electronic device 100 divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer.
[0056] The application layer can include a series of application packages.
[0057] like Figure 6 As shown, the application package may include applications such as video, music, map, WLAN, calendar, short message, gallery, call, navigation, Bluetooth, camera, etc.
[0058] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0059] like Figure 6 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0060] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0061] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0062] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0063] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0064] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0065] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0066] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0067] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0068] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0069] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0070] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0071] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0072] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0073] A 2D graphics engine is a drawing engine for 2D drawings.
[0074] The kernel layer is the layer between hardware and software. The kernel layer includes a kernel scheduling module, which can modify the priority of threads; it can also prioritize resources for the second thread within a preset time according to the instructions of the first thread. The kernel layer can also package various drivers. For example, the kernel layer includes display drivers, camera drivers, audio drivers, and sensor drivers.
[0075] Understandably, Figure 6 The layers in the software structure shown and the components included in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown, and each layer may include more or fewer components, which is not limited in the present application.
[0076] Figure 7 This is a flowchart showing an example of an application program running. The method for running the application program is executed by an electronic device. In this example, the electronic device is described by taking a mobile phone as an example. The process of running the application program includes:
[0077] Step 701: In response to a user operation on an application, a first thread in the application runs.
[0078] Specifically, multiple applications are installed in the mobile phone, and the mobile phone starts the application in response to the user's operation of starting the application. When the application is started (or the mini program is started, the scan result is displayed), the operating system of the mobile phone creates a process for the application, and the process includes one or more threads. The mobile phone allows multiple threads to run simultaneously. In this example, the first thread can be any thread in the running application. The user's operation on the application may include: starting the application, starting the mini program, scanning the QR code, and other operations.
[0079] Step 702: If the first thread in the application fails to lock the target resource and it is detected that the first thread belongs to the target thread, the target thread updates the first priority of the second thread to the second priority.
[0080] Specifically, when the first thread fails to lock the target resource, the first thread may detect whether the first thread belongs to the target thread. The target resource may be a data resource, a code resource, an input / output resource, etc.
[0081] Optionally, the first thread may detect whether the process to which the first thread belongs is in the foreground running state, and if it is detected that the process to which the first thread belongs is in the foreground running state, then detect whether the first thread is a key thread. The key thread may be the main thread in the process.
[0082] Optionally, there are multiple ways for the first thread to detect whether the process to which it belongs is in the foreground running state. For example, the first thread can detect whether a canvas is displayed in the process to which it belongs. If so, it is determined that the process to which the first thread belongs is in the foreground running state. Optionally, running attribute information of the running state can be set in the process. If the running attribute information is true, it indicates that the process is in the foreground running state. The first thread can obtain the running attribute information in the process to which the first thread belongs, and can determine whether the process to which the first thread belongs is in the foreground running state.
[0083] Optionally, when the first thread determines that the process to which it belongs is in the foreground running state, the first thread can detect whether the second identification information of the process to which the first thread belongs is the same as the third identification information of the first thread; if the first thread determines that the second identification information is the same as the third identification information, it is determined that the first thread belongs to a critical thread.
[0084] If the first thread detects that the process to which the first thread belongs is not in the foreground running state, the process ends.
[0085] When the first thread fails to load the target resource and it is detected that the first thread belongs to the target thread, the first thread updates the first priority of the second thread to the second priority, the second priority is higher than the first priority, and the second thread is the thread holding the lock of the target resource; the priority of the target thread is higher than the first priority.
[0086] Optionally, the second priority can be the highest priority within the priority range of the second thread. For example, the priority range of the second thread is 139 to 100, where the value 139 represents the lowest priority and the value 100 represents the highest priority. If the first priority is 139, the first thread can update the priority of the second thread from 139 to 100.
[0087] Optionally, the first thread can also increase the priority of the second thread by a preset level within a preset priority range. For example, the priority range is 139 to 100. If the first priority of the second thread is 139 and the preset level is 20, the first thread can update the priority of the second thread from 139 to 119.
[0088] Step 703: Before entering the blocking state, the target thread transmits the first identification information of the second thread to the kernel.
[0089] Specifically, since the first thread fails to lock and before entering the blocked state, the first thread may also transmit the first identification information of the second thread to the kernel. The first identification information may include the thread ID of the second thread. Optionally, the first identification information may also include first attribute information, which is used to indicate whether the kernel gives priority to calling resources for the thread corresponding to the first identification information. For example, the first attribute information is represented by "is_vip". If the value of the first attribute information is true, it indicates that the kernel determines to give priority to calling resources for the thread to which the first attribute belongs within a preset time length.
[0090] Step 704: The kernel preferentially schedules resources for the second thread within a preset time period according to the first identification information.
[0091] Specifically, the kernel obtains the first identification information and, according to the instruction in the first identification information, preferentially schedules resources for the second thread within a preset duration. Optionally, if the kernel sees that the first attribute information in the first identification information is true, it may preferentially schedule resources for the second thread within a preset duration.
[0092] Since the kernel prioritizes scheduling resources for the second thread, the second thread can frequently obtain CPU time slices, which speeds up the operation of the second thread. The CPU frequently allocates CPU time slices to the second thread, which reduces the probability of other threads obtaining CPU time slices. In order to avoid adverse effects on the operation of other threads, the time for the kernel to prioritize scheduling resources for the second thread should not be too long. In this example, the preset duration can be less than or equal to 20 milliseconds (such as the preset duration is 5 milliseconds, 10 milliseconds, 15 milliseconds, 20 milliseconds, etc.). When the kernel detects that the duration of the priority scheduling of resources for the second thread reaches the preset duration, the operation of prioritizing scheduling resources for the second thread ends.
[0093] Step 705: If the second thread does not release the lock within the preset time, it runs according to the second priority.
[0094] Specifically, if the second thread has not finished running within the preset time and has not released the lock, the kernel ends the operation of preferentially scheduling resources for the second thread. Since the priority of the second thread is updated to the second priority, the second thread runs according to the second priority. The second priority is higher than the first priority, and the second thread of the second priority will obtain the CPU time slice and schedule resources preferentially before the second thread of the first priority, thereby shortening the time the second thread holds the lock and shortening the time the first thread is blocked.
[0095] Optionally, after the second thread finishes running, the second thread releases the lock. The first thread is awakened by the second thread, and the first thread competes for the lock again and successfully locks. After successfully holding the lock, the first thread changes the second priority of the second thread to the first priority.
[0096] In this example, the electronic device can be a mobile phone, a bracelet, a tablet computer, a computer and other devices. The kernel only preferentially allocates resources to the second thread within a preset time length. When the second thread does not release the lock within the preset time length, the second thread runs according to the second priority. Since the second priority of the second thread is higher than the first priority, the processor can allocate resources to the second thread according to the second priority, thereby avoiding the problem that the second thread is preempted by other threads with higher priority than the first priority after exceeding the preset time length, resulting in the second thread being in a ready state and unable to release the lock in time. In this example, the method of modifying the priority of the second thread and the method of allocating resources to the second thread by the kernel within a preset time length are combined. The two methods complement each other, which can further shorten the time the second thread holds the lock and reduce the time the first thread is blocked, thereby solving the problems of slow data loading, frame loss and freeze on the startup page caused by the blocking of the first thread.
[0097] Figure 8 FIG. 1 is a schematic diagram showing the interaction between the first thread, the second thread and the kernel. Figure 8Describe in detail the process of running the application in this application.
[0098] In this example, thread A is taken as an example of the first thread, and thread C is taken as an example of the second thread.
[0099] When the lock of the target resource is in an unlocked state, if thread C performs a locking operation on the target resource, the lock of the target resource is in a light lock state. When other threads (such as thread D) access the target resource, thread D waits by spinning. When the number of times thread D spins exceeds the number threshold, the lock of the target resource will expand and upgrade from a light lock state to a heavy lock state. Alternatively, when the lock of the target resource is in a light lock state, when thread D is spinning and thread E accesses the target resource, the lock of the target resource will be upgraded from a light lock state to a heavy lock state.
[0100] The lock of the target resource is in a relocked state at time T1, at which time the thread C holds the Monitor object, wherein the Monitor object contains a lock instance (ie, a mutex instance, also referred to as mutex hereinafter).
[0101] Step 801: Thread A performs a lock operation on a target resource.
[0102] Specifically, at time T1, thread C holds the lock of the target resource, and the lock of the target resource is in a relocked state, and the Monitor object of the target resource is held by thread C. At time T2, thread A locks the target resource, that is, executes the MonitorEnter() method. Among them, time T2 is later than time T1. When thread A executes the MonitorEnter() method, thread A will try to obtain the Monitor object.
[0103] Step 802: Thread A attempts to lock, and fails to lock.
[0104] Specifically, thread A may attempt to hold the Monitor object through a CAS (Compare And Swap) algorithm. If the attempt fails, it is determined that thread A has failed to lock.
[0105] Step 803: Thread A detects whether it belongs to the target thread.
[0106] Specifically, thread A detects that the state of the lock is in a relocked state, and can detect whether thread A belongs to the target thread. Thread A first detects whether the process to which thread A belongs is in the foreground running state. If the process to which thread A belongs is in the foreground running state, thread A can obtain the identification information (i.e., PID) of the process to which thread A belongs, and compare the identification information of the process to which thread A belongs with the identification information of thread A. If thread A detects that the identification information (i.e., PID) of the process to which thread A belongs is consistent with the identification information of thread A (i.e., TID), it is determined that thread A is the key thread of the process to which thread A belongs, that is, thread A is the target thread.
[0107] In one example, since there is also a small program in the application program, the process to which thread A belongs may be the process of the small program.
[0108] It should be noted that, when thread A detects that the lock is in a relocked state, thread A can detect whether thread A is in the target thread through the Monitor object.
[0109] Thread A determines that thread A belongs to the target thread, and then executes step 804.
[0110] Step 804: If thread A detects that it belongs to the target thread, thread A changes the first priority of thread C to the second priority.
[0111] Specifically, if thread A detects that thread A belongs to the target thread, thread A can change the first priority of thread C to a second priority, which is higher than the first priority. Optionally, the second priority can be the highest priority within the priority range of thread C. For example, the range of ordinary priority is 139 to 100, where 139 is the lowest priority and 100 is the highest priority. The priority of thread C belongs to the ordinary priority, so thread A can change the priority of thread C to 100, which is the highest priority.
[0112] Optionally, thread A may also obtain the first priority of thread C, and determine the second priority according to the priority range of thread C. For example, if thread A detects that the first priority is within the priority range after increasing the preset level, thread A determines the second priority as the sum of the current first priority and the preset level (such as the preset level is -20, -15, -30, etc.), that is, the second priority = the first priority (139-20).
[0113] Step 805: Before entering the blocking state, thread A obtains the identification information of thread C from the lock.
[0114] Specifically, before entering the blocking state, thread A can obtain the identification information of thread C from the Monitor object or mutex. The Monitor object or mutex stores a pointer to the lock-holding thread, through which the identification information of the lock-holding thread (i.e., thread C) can be obtained, so that thread A can subsequently change the priority of the lock-holding thread (i.e., thread C).
[0115] In this example, thread A obtains the identification information of thread C from mutex.
[0116] Step 806: Thread A passes the identification information of thread C to the kernel.
[0117] Specifically, thread A transmits the first identification information of thread C to the kernel. The first identification information may include the ID number of the thread, and may also include first attribute information for indicating that the kernel should prioritize scheduling resources for thread C within a preset duration. For example, the first attribute information may be represented by "is_Vip". When the first attribute information is true, it indicates that the thread needs to schedule resources within the preset duration.
[0118] Step 807: The kernel schedules resources for thread C preferentially.
[0119] Specifically, when the kernel obtains the thread ID number and the first attribute information in the first identification information, the timer can be started to prioritize scheduling resources for thread C within the preset duration. For example, the kernel receives the first identification information, recognizes that the ID number and the first attribute information of thread C are true, and then starts the timer to start timing, wherein the preset duration is less than or equal to 20 milliseconds, such as the preset duration is 20 milliseconds, 15 milliseconds, 10 milliseconds, etc. In this example, the preset duration is illustrated by taking 20 milliseconds as an example. Within 20 milliseconds, the kernel can frequently allocate resources to thread C, that is, thread C can frequently occupy the CPU within 20 milliseconds. When the kernel detects that the timer reaches 20 milliseconds, the operation of allocating resources to thread C is immediately terminated. Optionally, the preset duration can also be detected by a timer.
[0120] Step 808: After the preset time is reached, the kernel ends the operation of prioritizing resource scheduling for thread C.
[0121] Specifically, the kernel may delete the first identification information after completing the operation of preferentially scheduling resources for thread C.
[0122] Optionally, if thread C finishes running within a preset time and releases the lock, the kernel may also end the operation of prioritizing resource scheduling for thread C.
[0123] Step 809: Thread C runs at the second priority.
[0124] Specifically, if thread C does not release the lock within the preset time, thread C will run at the modified second priority because the kernel has finished scheduling resources for thread C. Since the second priority of thread C is higher than the first priority, the probability of thread C being preempted by other threads during its running is reduced, thereby reducing the problem of thread A being blocked for a long time.
[0125] If the second priority is the highest priority, the problem of CPU being preempted by other threads can be avoided, the time that thread C is in the ready state is shortened, the lock holding time of thread C is further reduced, and the time that thread A is blocked is reduced.
[0126] Step 810: Thread C releases the lock.
[0127] Specifically, when thread C finishes running, the lock can be released, that is, thread C releases the monitor object.
[0128] Step 811: Thread A is awakened.
[0129] Specifically, because thread C releases the Monitor object, thread A is awakened and step 811 is executed.
[0130] Step 812: Thread A holds the lock successfully.
[0131] Specifically, after thread C releases the lock, thread A attempts to lock the target resource again. Since the lock of the target resource is in a relocked state and is not held by the thread at this time, thread A successfully holds the lock.
[0132] Step 813: Thread A updates the second priority of thread C to the first priority.
[0133] Specifically, after thread C releases the lock, thread A successfully holds the lock and ends the blocking. Thread A can update the second priority of thread C to the first priority. Changing the priority of thread C to the first priority avoids unnecessary impact of thread C on other threads in a high priority state.
[0134] Fig. 9 The diagram is a schematic diagram showing an exemplary thread calling a CPU using the method for running an application program in the present application.
[0135] like Fig. 9 As shown in the figure, thread A is the main thread in the startup process of application A. The priority of thread A is higher than that of thread C. The priority of thread A is higher than that of thread B, and the priority of thread B is higher than that of thread C. Thread C locked the shared resource at time T0, and the lock is in the relocked state. Thread A locked the shared resource at time T1, but because the lock of the target resource is already held by thread C, thread A failed to compete for the lock. Fig. 9As shown by the dotted arrow in the figure, the first priority of thread C (such as 139) is changed to the second priority, and the second priority is the highest priority (such as 100) within the priority range of thread C. Thread A obtains the first identification information of thread C, which includes the identity ID of thread C and the first attribute information, and the first attribute information indicates true. Thread A transmits the first identification information of thread C to the kernel, and the kernel obtains the first identification information, starts the timer, and the kernel preferentially schedules resources for thread C. When the kernel detects that the timer reaches the preset duration (such as T1-T2), the operation of preferentially scheduling resources for thread C ends. Thread C does not release the lock within the preset duration, and thread C will run at priority 100. Since the priority of thread C is 100 and the priority of thread B is 120, the priority of thread C is higher than that of thread B, and thread C will preferentially schedule resources, that is, thread C will preferentially allocate CPU time slices, and thread B is in the ready state. Thread C releases the lock at time T3, and thread A locks the target resource. Thread A successfully locks the target resource. Thread A can modify the priority of thread C to the first priority (i.e. 139). At this time, the priority of thread B is 120, and it can obtain the CPU time slice. As the running time of thread C is shortened, the blocking time of thread A is shortened, thus solving the problem of frame loss and freeze on the startup page due to long blocking time of thread A, and also solving the problem of long time to display the scan result due to long blocking time of thread A.
[0136] In some embodiments, when the first thread in the application fails to lock the target resource and it is detected that the first thread is the target thread, the priority of the current lock-holding thread can be increased so that the lock-holding thread can preempt other threads to seize the CPU, thereby reducing the running time of the lock-holding thread and thereby shortening the time the first thread is blocked, thereby solving the problem of frame loss and freeze in the application.
[0137] Fig.10 The flowchart of an application program running is shown as an example, and the process includes:
[0138] Step 1001: The second thread successfully locks the target resource.
[0139] In this example, the second thread successfully locks the target resource. When the lock state of the target resource is in a relocked state, the second thread holds the lock of the target resource.
[0140] Step 1002: The first thread attempts to lock the target resource.
[0141] Specifically, the priority of the first thread is higher than the priority of the second thread. The first thread can attempt to lock the target resource. If the lock state of the target resource is in a re-locked state, it can be detected whether the re-lock is released by the holding thread, that is, step 1003 is executed.
[0142] Step 1003: The first thread detects whether the lock of the target resource is held by other threads.
[0143] Specifically, the first thread may detect whether the lock of the target resource is released by attempting to lock. If the locking attempt fails, it may be determined that the lock of the target resource is held by other threads.
[0144] Step 1004: If the first thread detects that the lock of the target resource is held by other threads, the first thread detects whether it belongs to the target thread.
[0145] This process is similar to step 803, and reference may be made to the description in step 803, which will not be repeated here.
[0146] Step 1005: If the first thread detects that the first thread belongs to the target thread, the first thread updates the first priority of the second thread to the second priority.
[0147] This process is similar to step 804, and the description in step 804 may be referred to, and will not be repeated here. After the priority of the second thread is the second priority, the second thread runs according to the second priority, that is, step 1007 is executed.
[0148] Step 1006: The first thread is in a blocked state, waiting for the second thread to release the lock of the target resource.
[0149] Specifically, after the first thread changes the priority of the second thread to the second priority, the first thread enters a blocked state and waits for the second thread to release the lock of the target resource.
[0150] Step 1007: The second thread runs according to the second priority, and the processor schedules resources for the second thread according to the second priority.
[0151] This process is similar to step 809, and you can refer to the description in step 809, which will not be repeated here.
[0152] Step 1008: The second thread releases the lock.
[0153] Specifically, after the second thread finishes running according to the second priority, the lock of the target resource can be released.
[0154] Step 1009: The first thread successfully locks the target resource, and the second priority of the second thread is updated to the first priority.
[0155] After the second thread releases the lock, the first thread successfully locks and the first thread resumes running. The first thread can update the second priority of the second thread to the first priority.
[0156] Fig.11 Schematic diagram of the interaction between the first thread and the second thread. Fig.11 Describe in detail the process of running the application in this application.
[0157] Step 1101: Thread A performs a lock operation on the target resource.
[0158] Step 1102: Thread A attempts to lock, and fails to lock.
[0159] Step 1103: Thread A detects whether it belongs to the target thread.
[0160] Step 1104: If thread A detects that it belongs to the target thread, thread A changes the first priority of thread C to the second priority.
[0161] Steps 1101 to 1104 are similar to steps 801 to 804 , and reference may be made to the relevant descriptions in steps 801 to 804 , which will not be repeated here.
[0162] Step 1105: Thread C runs at the second priority.
[0163] Specifically, since the second priority of thread C is higher than the first priority, the probability of CPU being preempted by other threads during the running of thread C is reduced, thereby reducing the problem of thread A being blocked for a long time.
[0164] If the second priority is the highest priority, the problem of CPU being preempted by other threads can be avoided, the time that thread C is in the ready state is shortened, the running time of thread C is further reduced, and the time that thread A is blocked is reduced.
[0165] Step 1106: Thread C releases the lock.
[0166] Step 1107: Thread A is awakened.
[0167] Step 1108: Thread A holds the lock successfully.
[0168] Step 1109: Thread A updates the second priority of thread C to the first priority.
[0169] Steps 1106 to 1109 are similar to steps 810 to 813 , and reference may be made to the relevant descriptions in steps 810 to 813 , which will not be repeated here.
[0170] It is understandable that, in order to realize the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.
[0171] This embodiment also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the method for running the application program in the above-mentioned embodiment. The storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0172] This embodiment also provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement the method for running the application program in the above-mentioned embodiment.
[0173] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.
[0174] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0175] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first target object and a second target object are used to distinguish different target objects rather than to describe a specific order of target objects.
[0176] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0177] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two. For example, multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.
[0178] Any content of each embodiment of the present application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of the present application.
[0179] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A method for running an application program, It is characterized in that include: In response to a user operation on an application, a first thread in the application runs; When the first thread fails to lock the target resource and the first thread detects that the first thread belongs to the target thread, the first thread updates the first priority of the second thread to the second priority so that the second thread runs according to the second priority, the second priority is higher than the first priority, and the second thread is the thread holding the lock of the target resource; the target thread is the main thread in the process to which it belongs and the process to which the target thread belongs is in the foreground running state, and the priority of the target thread is higher than the first priority; When the second thread runs at the second priority level, when the first thread successfully locks the target resource, the first thread updates the second priority level of the second thread to the first priority level; The target resources include: data resources, code resources or input / output resources.
2. The method according to claim 1, It is characterized in that After the first thread updates the first priority of the second thread to a second priority, the method further includes: The first thread transmits the first identification information of the second thread to the kernel, so that the kernel preferentially schedules resources for the second thread within a preset time period according to the first identification information; The second thread is used to run according to the second priority level when the lock is not released within the preset time period.
3. The method according to claim 1 or 2, It is characterized in that The method further comprises: The first thread performs a locking operation on the target resource; When the first thread detects that the lock of the target resource is re-locked and the lock has not been released by the second thread, the first thread determines that locking the target resource has failed.
4. The method according to claim 1 or 2, It is characterized in that The first thread detecting whether the first thread belongs to the target thread includes: The first thread detects whether the process to which the first thread belongs is in the foreground running state; When the first thread determines that the process to which the first thread belongs is in the foreground running state, the first thread detects whether the first thread is a key thread, and the key thread is a main thread in the process to which the first thread belongs; When the first thread detects that the first thread is a critical thread, the first thread determines that the first thread belongs to a target thread.
5. The method according to claim 4, It is characterized in that The detecting whether the first thread is a critical thread includes: The first thread obtains second identification information of the process to which the first thread belongs; The first thread determines whether the second identification information is the same as the third identification information of the first thread; When the first thread detects that the second identification information is the same as the third identification information, the first thread determines that the first thread is a key thread; When the first thread detects that the second identification information is different from the third identification information, the first thread determines that the first thread is not a critical thread.
6. The method according to claim 2, It is characterized in that The kernel is used for starting a timer when the first identification information is acquired; The kernel is further configured to terminate the operation of preferentially scheduling resources for the second thread when detecting that the duration recorded by the timer reaches the preset duration.
7. The method according to claim 2, It is characterized in that The first identification information includes: an identification number of the second thread and first attribute information, where the first attribute information is used to indicate whether the kernel preferentially schedules resources for the second thread.
8. The method according to claim 1, It is characterized in that The first thread updates the first priority of the second thread to the second priority, including: When the first thread detects that the lock is re-locked, the first thread obtains first identification information of the second thread; The first thread updates the first priority to a second priority through an interface according to the first identification information.
9. The method according to claim 2, It is characterized in that The preset duration is less than or equal to 20 milliseconds.
10. The method according to claim 1, It is characterized in that The first thread belongs to the application or to an applet in the application.
11. An electronic device, It is characterized in that include: a memory and a processor, the memory being coupled to the processor; The memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the method for running an application program as described in any one of claims 1-10.
12. A computer-readable storage medium comprising a computer program, It is characterized in that When the computer program is executed on an electronic device, the electronic device executes the method for executing an application executed by the electronic device as claimed in any one of claims 1 to 10.
