Application thread processing method and deviceTechnical Field
The invention relates to the technical field of internet application, in particular to a method and a device for processing an application thread.
Background
With the popularization of mobile terminal devices such as smart phones and tablet computers, people are gradually accustomed to a mode of surfing the internet by using APP (Application) clients, and all domestic large electronic businesses at present have own APP clients.
In practical applications, there may be situations where the application is not responsive, for example, an input box is displayed, but there is no focus in the input box; or, there is focus in the input box, but the virtual keyboard is not popped up, and so on, there is a need to solve this problem.
Disclosure of Invention
The invention provides a processing method and a processing device of an application thread, which are used for solving the problem of no response of an application.
The invention provides a processing method of an application thread, which comprises the following steps:
monitoring the running time of each task of a main thread in the running process of the main thread of an application;
and if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule.
In an embodiment of the present invention, monitoring the running time of each task of the main thread includes:
starting a timer when each task is executed in the main thread;
and timing each task by utilizing the timer so as to monitor the running time of each task of the main thread.
In an embodiment of the present invention, processing the main thread by using a preset processing rule includes:
killing the main thread; or,
and generating prompt information for prompting the user not to perform other operations aiming at the application.
In an embodiment of the present invention, the method further includes:
and shielding the hardware button operation aiming at the application.
In an embodiment of the present invention, before monitoring the running time of each task of the main thread, the method further includes:
judging whether the number of tasks of the main thread exceeds a number threshold;
and if so, monitoring the running time of each task of the main thread.
The invention also provides a processing device of the application thread, which comprises:
the monitoring module is used for monitoring the running time of each task of the main thread in the running process of the main thread of the application;
and the processing module is used for processing the main thread by adopting a preset processing rule if the running time of the task exceeds the specified time.
In an embodiment of the present invention, the monitoring module is further configured to:
starting a timer when each task is executed in the main thread;
and timing each task by utilizing the timer so as to monitor the running time of each task of the main thread.
In an embodiment of the present invention, the processing module is further configured to:
killing the main thread; or,
and generating prompt information for prompting the user not to perform other operations aiming at the application.
In an embodiment of the present invention, the processing module is further configured to:
and shielding the hardware button operation aiming at the application.
In an embodiment of the present invention, the apparatus further includes:
the judging module is used for judging whether the number of the tasks of the main thread exceeds a number threshold value; and if so, monitoring the running time of each task of the main thread.
In the embodiment of the invention, in the process of running a main thread of an application, the running time of each task of the main thread is monitored; and if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule. Therefore, the embodiment of the invention can solve the problem of no response of the application.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
The technical solution of the present invention is further described in detail by the accompanying drawings and embodiments.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the principles of the invention and not to limit the invention. In the drawings:
FIG. 1 is a flow chart illustrating a method for processing application threads according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a method for processing application threads according to another embodiment of the present invention;
FIG. 3 is a schematic diagram illustrating a structure of a processing device applying threads according to an embodiment of the present invention; and
FIG. 4 is a schematic structural diagram of a processing device using threads according to another embodiment of the present invention.
Detailed Description
The preferred embodiments of the present invention will be described in conjunction with the accompanying drawings, and it will be understood that they are described herein for the purpose of illustration and explanation and not limitation.
Fig. 1 is a flowchart illustrating a processing method for application threads, which may be applied to a terminal such as a smart phone or a smart tv set, according to an embodiment of the present invention, and the method may include the following steps S11-S12.
Step S11, during the process of the main thread running of the application, the running time of each task of the main thread is monitored.
And step S12, if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule.
In the embodiment of the invention, in the process of running a main thread of an application, the running time of each task of the main thread is monitored; and if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule. Therefore, the embodiment of the invention can solve the problem of no response of the application.
In the above step S11, the running time of each task of the main thread is monitored, and an alternative solution is provided in the embodiment of the present invention, which includes the following steps a1-a 2.
Step A1, a timer is started when each task is executed in the main thread.
And step A2, timing each task by using a timer to monitor the running time of each task of the main thread.
The embodiment of the invention adds the timing management of the operation of the main thread to monitor the operation time of each task of the main thread, and further processes the main thread by adopting the preset processing rule when the operation time of the task exceeds the specified time.
In the step S12, the main thread is processed by using the preset processing rule, the embodiment of the present invention provides an optional scheme, where the scheme may be to kill the main thread; or, generating a prompt message for prompting the user not to perform other operations with respect to the application, and so on, which is not limited by the present invention.
In an optional embodiment of the present invention, if the running time of the task exceeds a specified time, the hardware button operation for the application may be further masked.
In an alternative embodiment of the present invention, before monitoring the running time of each task of the main thread in step S11 above, it may be determined whether the number of tasks of the main thread exceeds a number threshold; and if so, monitoring the running time of each task of the main thread. Otherwise, the monitoring operation may not be performed.
In an alternative embodiment of the invention, it may also be monitored whether the main thread in the application is in star state. If so, it indicates that the main thread is a time consuming thread and needs to be killed. The main thread is typically the thread used for the interface display and can therefore be killed. In one application, each interface has a unique main thread, so when the current interface is displayed, the main thread of the current interface cannot be killed, otherwise, the current interface is destroyed. Thus, it is possible to monitor whether a time-consuming task or operation is in the main thread of the current interface to affect the display of the interface.
The following describes in detail the implementation process of the application thread processing method according to the present invention by using a specific embodiment. Fig. 2 is a flowchart illustrating a processing method for application threads in another embodiment of the present invention, where the method may be applied to a terminal such as a smart phone or a smart tv, and the method may include the following steps S21-S23.
Step S21, in the process of the main thread running, judging whether the number of tasks of the main thread exceeds the number threshold, if yes, continuing to execute step S22; otherwise, if not, the determination operation of step S21 is continued.
And step S22, starting a timer, and timing each task by using the timer so as to monitor the running time of each task of the main thread.
And step S23, if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule.
In this step, the main thread may be killed; or, generating a prompt message for prompting the user not to perform other operations with respect to the application, and so on, which is not limited by the present invention. In addition, hardware button operations for the application may also be masked.
It should be noted that, in practical applications, all the above-mentioned optional embodiments may be combined in a combined manner at will to form an optional embodiment of the present invention, and details are not described here any more.
Corresponding to the processing method of the application thread in the above embodiment, the present invention also provides a processing apparatus of the application thread. Fig. 3 is a schematic structural diagram of a processing apparatus for applying threads according to an embodiment of the present invention, including:
the monitoring module 31 is configured to monitor an operation duration of each task of a main thread during an operation process of the main thread of an application;
and the processing module 32 is configured to process the main thread by using a preset processing rule if the running time of the task exceeds a specified time.
In an embodiment of the present invention, the monitoring module 31 is further configured to:
starting a timer when each task is executed in the main thread;
and timing each task by utilizing the timer so as to monitor the running time of each task of the main thread.
In an embodiment of the present invention, the processing module 32 is further configured to:
killing the main thread; or,
and generating prompt information for prompting the user not to perform other operations aiming at the application.
In an embodiment of the present invention, the processing module 32 is further configured to:
and shielding the hardware button operation aiming at the application.
In an embodiment of the present invention, as shown in fig. 4, the apparatus shown in fig. 3 above may further include:
a judging module 41, configured to judge whether the number of tasks of the main thread exceeds a number threshold; and if so, monitoring the running time of each task of the main thread.
The above device of the embodiment of the present invention: monitoring the running time of each task of a main thread in the running process of the main thread of an application; and if the running time of the task exceeds the specified time, processing the main thread by adopting a preset processing rule. Therefore, the embodiment of the invention can solve the problem of no response of the application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.