CN108563581A - Abnormality detection processing method and apparatus, electronic device, and computer storage medium - Google Patents
Abnormality detection processing method and apparatus, electronic device, and computer storage medium Download PDFInfo
- Publication number
- CN108563581A CN108563581A CN201810381722.4A CN201810381722A CN108563581A CN 108563581 A CN108563581 A CN 108563581A CN 201810381722 A CN201810381722 A CN 201810381722A CN 108563581 A CN108563581 A CN 108563581A
- Authority
- CN
- China
- Prior art keywords
- thread group
- exception
- exception handling
- thread
- handling method
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3604—Analysis of software for verifying properties of programs
- G06F11/3608—Analysis of software for verifying properties of programs using formal methods, e.g. model checking, abstract interpretation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/362—Debugging of software
- G06F11/3644—Debugging of software by instrumenting at runtime
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Debugging And Monitoring (AREA)
Abstract
本发明实施例公开了一种异常检测处理方法及装置、电子设备及计算机存储介质。所述异常检测处理方法包括:创建第一线程组;在所述第一线程组内创建异常处理方法;利用所述第一线程组替代应用程序的第二线程组进行异常处理。
The embodiment of the invention discloses an anomaly detection and processing method and device, electronic equipment, and a computer storage medium. The abnormal detection processing method includes: creating a first thread group; creating an exception processing method in the first thread group; using the first thread group to replace the second thread group of the application program to perform exception processing.
Description
技术领域technical field
本发明涉及信息技术领域,尤其涉及一种异常检测处理方法及装置、电子设备及计算机存储介质。The present invention relates to the field of information technology, in particular to an abnormality detection and processing method and device, electronic equipment and computer storage medium.
背景技术Background technique
应用程序,在运行时可能会因为某些异常原因导致程序崩溃,为了便于开发者获取程序崩溃原因,会对应用程序的异常进行捕获,例如,安卓应用(Application,APP)中,主要是通过设置线程的自定义异常捕获处理类,从而通过自定义异常捕获处理类中捕获崩溃异常,在捕获异常之后,才可能对异常进行修复,使得APP能够整体上运行良好,确保用户的使用满意度。但是实践发现,在一些情况下,APP的异常捕获存在遗漏问题或异常捕获中途中断问题。The application program may crash due to some abnormal reasons during operation. In order to facilitate the developer to obtain the cause of the program crash, the exception of the application program will be captured. For example, in the Android application (Application, APP), mainly through setting The thread's custom exception capture processing class, so as to capture the crash exception through the custom exception capture processing class. After the exception is caught, it is possible to repair the exception, so that the APP can run well as a whole and ensure user satisfaction. However, practice has found that in some cases, there are omissions or interruptions in the exception capture of the APP in the exception capture.
发明内容Contents of the invention
有鉴于此,本发明实施例期望提供一种异常检测处理方法及装置、电子设备及计算机存储介质,至少部分解决APP异常捕获等异常处理遗漏的问题。In view of this, the embodiments of the present invention expect to provide an anomaly detection and processing method and device, electronic equipment, and computer storage medium, which at least partially solve the problem of missing exception processing such as APP exception capture.
本发明的技术方案是这样实现的:Technical scheme of the present invention is realized like this:
第一方面,本发明实施例提供一种异常检测处理方法,包括:In a first aspect, an embodiment of the present invention provides an abnormality detection and processing method, including:
创建第一线程组;Create the first thread group;
在所述第一线程组内创建异常处理方法;creating an exception handling method within the first thread group;
利用所述第一线程组替代应用程序的第二线程组进行异常处理。Using the first thread group to replace the second thread group of the application program for exception handling.
可选地,所述在所述第一线程组内创建异常处理方法,包括:Optionally, the creating an exception handling method in the first thread group includes:
在所述第一线程组内创建第二异常处理方法;creating a second exception handling method within the first thread group;
将所述应用程序的第一异常处理方法的方法名设置为所述第二异常处理方法的方法名。Set the method name of the first exception handling method of the application as the method name of the second exception handling method.
可选地,所述第二异常处理方法的异常处理逻辑,至少部分不同于所述第一异常处理方法的异常处理逻辑。Optionally, the exception handling logic of the second exception handling method is at least partially different from the exception handling logic of the first exception handling method.
可选地,所述第二异常方法包括:Optionally, the second exception method includes:
继承的所述第一异常处理方法;Inherited said first exception handling method;
创建的第三异常处理方法;其中,所述第三异常处理方法的异常处理逻辑不同于所述第一异常处理方法的异常处理逻辑。A third exception handling method is created; wherein, the exception handling logic of the third exception handling method is different from the exception handling logic of the first exception handling method.
可选地,所述在所述第一线程组内创建异常处理方法,包括:Optionally, the creating an exception handling method in the first thread group includes:
利用覆写机制在所述第一线程组内创建所述异常处理方法。The exception handling method is created in the first thread group by using an overriding mechanism.
可选地,所述方法还包括以下至少之一:Optionally, the method also includes at least one of the following:
根据所述第二线程组的属性设置所述第一线程组的属性;setting the attributes of the first thread group according to the attributes of the second thread group;
根据所述第二线程组的引用设置所述第一线程组的引用。Setting the reference of the first thread group based on the reference of the second thread group.
可选地,所述根据所述第二线程组的属性设置所述第一线程组的属性,包括以下至少之一:Optionally, the setting the attribute of the first thread group according to the attribute of the second thread group includes at least one of the following:
根据所述第二线程组的线程组名称设置所述第一线程组的线程组名称;Setting the thread group name of the first thread group according to the thread group name of the second thread group;
根据所述第二线程组包括的线程信息设置所述第一线程组包括的线程组信息;Setting the thread group information included in the first thread group according to the thread information included in the second thread group;
根据所述第二线程组的类型设置所述第一线程组的类型,其中,所述类型包括:前台线程组类型和/或后台线程组类型。The type of the first thread group is set according to the type of the second thread group, wherein the type includes: a foreground thread group type and/or a background thread group type.
可选地,所述根据所述第二线程组的属性设置所述第一线程组的属性,包括:Optionally, the setting the attribute of the first thread group according to the attribute of the second thread group includes:
利用反射机制根据所述第二线程组的属性设置所述第一线程组的属性。Using a reflection mechanism to set the attributes of the first thread group according to the attributes of the second thread group.
可选地,所述利用所述第一线程组替代应用程序的第二线程组进行异常处理,包括:Optionally, using the first thread group to replace the second thread group of the application program to perform exception handling includes:
所述第一线程组从操作系统接收异常捕获事件;The first thread group receives an exception capture event from an operating system;
所述第一线程组的异常捕获方法基于异常捕获事件执行异常捕获。The exception catching method of the first thread group performs exception catching based on an exception catching event.
第二方面,本发明实施例提供一种异常检测处理装置,包括:In a second aspect, an embodiment of the present invention provides an abnormality detection and processing device, including:
第一创建模块,用于创建第一线程组;The first creation module is used to create the first thread group;
第二创建模块,用于在所述第一线程组内创建异常处理方法;A second creating module, configured to create an exception handling method in the first thread group;
替代处理模块,用于利用所述第一线程组替代应用程序的第二线程组进行异常处理。The replacement processing module is used to use the first thread group to replace the second thread group of the application program to perform exception processing.
第三方面,本发明实施例提供一种电子设备,包括:In a third aspect, an embodiment of the present invention provides an electronic device, including:
存储器,用于信息存储;memory for information storage;
处理器,与所述存储器连接,用于通过执行存储在所述存储器上的计算机可执行指令,实现前述一个或多个技术方案提供的方法。A processor, connected to the memory, configured to implement the method provided by the foregoing one or more technical solutions by executing computer-executable instructions stored in the memory.
第四方面,本发明实施例提供一种计算机存储介质,所述计算机存储介质存储有计算机可执行指令;所述计算机可执行指令被执行后,能够前述一个或多个技术方案提供的方法。In a fourth aspect, an embodiment of the present invention provides a computer storage medium, the computer storage medium stores computer-executable instructions; after the computer-executable instructions are executed, the method provided by one or more of the foregoing technical solutions can be implemented.
本发明实施例提供的异常检测处理方法及装置、电子设备及计算机存储介质,会创建一个第一线程组,通过第一线程组的线程组级别的异常处理方法替代第二线程组进行异常捕获等异常处理,从而减少线程级别的异常捕获事件不相互传递导致异常捕获遗漏的问题,从而实现全面的异常处理,减少异常捕获等异常处理等遗漏现象或中断现象。The anomaly detection and processing method and device, electronic equipment, and computer storage medium provided by the embodiments of the present invention will create a first thread group, and use the thread group-level exception processing method of the first thread group to replace the second thread group to perform exception capture, etc. Exception handling, so as to reduce the problem that the thread-level exception catching events are not transmitted to each other, resulting in missing exception catching, so as to achieve comprehensive exception handling, and reduce omissions or interruptions such as exception catching and other exception handling.
附图说明Description of drawings
图1为本发明实施例提供的第一种异常检测处理方法的流程示意图;Fig. 1 is a schematic flow chart of the first abnormality detection and processing method provided by the embodiment of the present invention;
图2为本发明实施例提供的一种电子设备的系统框图;FIG. 2 is a system block diagram of an electronic device provided by an embodiment of the present invention;
图3为本发明实施例提供的一种电子设备的结构示意图;FIG. 3 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention;
图4为本发明实施例提供的第二种异常检测处理方法的流程示意图。FIG. 4 is a schematic flowchart of a second anomaly detection and processing method provided by an embodiment of the present invention.
具体实施方式Detailed ways
以下结合说明书附图及具体实施例对本发明的技术方案做进一步的详细阐述。The technical solutions of the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
研究发现导致异常捕获遗漏问题或中断问题的是:在相关技术都是进行线程级别的异常捕获;操作系统发现异常之后,通知线程组;线程组告知率先建立异常捕获方法的线程进行异常捕获;若一个线程在完成异常捕获之后,不将异常捕获事件传递给其他程序,则会导致捕获的中断,进而导致异常捕获遗漏问题。若一个应用程序中有引入第三软件开发工具(Software Development Kit,SDK)或第三方插件,由于异常程序中自身开发的异常程序不会知晓第三方提供的SDK或第三方插件,显然就更不可能将异常捕获事件传递给第三方SDK或第三方插件,故导致安装有第三方SDK或第三方插件的应用程序的异常检测总是有遗漏。The research found that the problem of missing or interrupting the exception capture is: in the related technologies, the exception capture at the thread level is carried out; after the operating system finds the exception, it notifies the thread group; the thread group informs the thread that first established the exception capture method to capture the exception; if After a thread completes the exception capture, if it does not pass the exception capture event to other programs, it will cause the interruption of the capture, which will lead to the problem of missing exception capture. If a third-party software development tool (Software Development Kit, SDK) or a third-party plug-in is introduced into an application program, since the abnormal program developed by itself in the abnormal program will not know the SDK or third-party plug-in provided by the third party, it is obviously even worse. The exception capture event may be passed to the third-party SDK or third-party plug-in, so the exception detection of the application installed with the third-party SDK or third-party plug-in is always missing.
如图1所示,本实施例提供一种异常检测处理方法,包括:As shown in FIG. 1, this embodiment provides a method for abnormality detection and processing, including:
步骤S110:创建第一线程组;Step S110: creating a first thread group;
步骤S120:在所述第一线程组内创建异常处理方法;Step S120: Create an exception handling method in the first thread group;
步骤S130:利用所述第一线程组替代应用程序的第二线程组进行异常处理。Step S130: Use the first thread group to replace the second thread group of the application program to perform exception handling.
本实施例中所述第一线程组可为独立于所述第二线程组。所述第二线程组可为能够接收到操作系统提供的异常捕获事件的任意一个线程组,例如,所述第二线程组可为主函数所在的主线程组,所述主函数可包括:main()函数。再例如,所述第二线程组还可以是其他用于异常捕获等异常处理的线程组,不局限于所述主函数所在的主线程组。In this embodiment, the first thread group may be independent from the second thread group. The second thread group can be any thread group that can receive the exception capture event provided by the operating system. For example, the second thread group can be the main thread group where the main function is located, and the main function can include: main ()function. For another example, the second thread group may also be other thread groups used for exception handling such as exception capture, and is not limited to the main thread group where the main function is located.
在本实施例中,所述第一线程组可为临时或动态创建的线程组。In this embodiment, the first thread group may be a temporary or dynamically created thread group.
在一些实施例中,步骤S110可包括:在应用程序启动时或启动后,创建所述第一线程组。如此,每次应用程序启动时或启动后创建所述第一线程组,即便应用程序有更新(例如,有引入新的插件或补丁等)可以及时的调整第一线程组内包括的异常处理方法,实现异常捕获等异常的全面处理,避免遗漏及异常处理中断的问题。In some embodiments, step S110 may include: creating the first thread group when the application starts or after starting. In this way, the first thread group is created every time the application program starts or after startup, even if the application program is updated (for example, a new plug-in or patch is introduced), the exception handling method included in the first thread group can be adjusted in time , to achieve comprehensive handling of exceptions such as exception capture, avoiding omissions and exception handling interruptions.
在一些实施例中,所述步骤S110还可包括:在应用程序有更新时,创建所述第一线程组;否则利用前一次应用程序关闭之前创建的第一线程组进行异常处理,减少第一线程组创建等过程。此处,应用程序有更新可包括:异常程序的代码更新和/或配置信息,例如,应用程序有新增插件和/或新增补丁等。In some embodiments, the step S110 may further include: when the application program is updated, creating the first thread group; otherwise, using the first thread group created before the previous application program is closed for exception handling, reducing the first Processes such as thread group creation. Here, the update of the application program may include: code update and/or configuration information of the abnormal program, for example, the application program has a new plug-in and/or a new patch.
在一些实施例中,在应用程序中设置有创建第一线程组的执行代码及执行参数,该执行代码被调用后会基于所述执行参数创建所述第一线程组,所述执行参数可包括:所述第一线程组的线程组对象等参数。在另一些实施例中,所述执行代码被调用还可包括:向操作系统申请创建和使用所述第一线程组的资源,所述资源可包括:存储资源和/或计算资源等。In some embodiments, an execution code and execution parameters for creating the first thread group are set in the application program. After the execution code is called, the first thread group will be created based on the execution parameters. The execution parameters may include : Parameters such as the thread group object of the first thread group. In some other embodiments, the calling of the executing code may further include: applying to the operating system for creating and using the resources of the first thread group, and the resources may include: storage resources and/or computing resources, and the like.
在本实施例中可基于第一线程组的线程组类,创建所述第一线程组;例如,创建与第二线程组相同类型的第一线程组。In this embodiment, the first thread group may be created based on the thread group class of the first thread group; for example, the first thread group of the same type as the second thread group is created.
在第一线程组内创建异常处理方法,该异常处理方法可为各种程序代码,直接归属于线程组的异常处理方法。An exception handling method is created in the first thread group, and the exception handling method can be various program codes, which directly belong to the exception handling method of the thread group.
在本实施例中利用创建的第二线程组直接进行异常处理,如此,若操作系统发现了异常会产生异常捕获事件并告知第二线程组;直接利用第二线程组内的异常处理方法进行异常捕获,显然就不存在不同线程之间的异常捕获的传递,就不存在因为异常捕获事件传递中断导致的异常捕获遗漏的问题。操作系统发送的异常捕获事件会触发对应的线程组或线程进行异常处理,例如,所述异常处理可包括:异常捕获、异常定位、异常记录及异常上报中的一个或多个。In this embodiment, the second thread group created is used to directly perform exception handling, so if the operating system finds an exception, an exception capture event will be generated and the second thread group notified; Capture, obviously there is no transfer of exception capture between different threads, and there is no problem of missing exception capture due to interruption of exception capture event transmission. The exception catching event sent by the operating system will trigger the corresponding thread group or thread to perform exception handling. For example, the exception handling may include: one or more of exception catching, exception locating, exception recording, and exception reporting.
可选地,所述步骤S120可包括:Optionally, the step S120 may include:
在所述第一线程组内创建第二异常处理方法;creating a second exception handling method within the first thread group;
将所述应用程序的第一异常处理方法的方法名设置为所述第二异常处理方法的方法名。Set the method name of the first exception handling method of the application as the method name of the second exception handling method.
可选地,所述第二异常处理方法的异常处理逻辑,至少部分不同于所述第一异常处理方法的异常处理逻辑。Optionally, the exception handling logic of the second exception handling method is at least partially different from the exception handling logic of the first exception handling method.
在本实施例中为了实现异常捕获的处理,能够顺利将捕获的异常告知服务器平台。在本实施例中会创建第二异常处理方法,该第二异常处理方法可为:应用程序的线程组级别的异常处理逻辑和/或线程级别的异常处理逻辑继承过来。例如,继承第二线程组的线程组级别的异常处理逻辑、继承应用程序中不同线程的异常处理逻辑,如此,不管该线程级别的异常处理逻辑是应用程序自身默认设置的,还是第三SDK或第三插件的线程级别的异常处理逻辑都会被继承到。In this embodiment, in order to realize the processing of exception capture, the server platform can be smoothly notified of the caught exception. In this embodiment, a second exception handling method is created, and the second exception handling method may be: the exception handling logic at the thread group level and/or the exception handling logic at the thread level of the application program are inherited. For example, inherit the exception handling logic at the thread group level of the second thread group, and inherit the exception handling logic of different threads in the application program. In this way, no matter whether the exception handling logic at the thread level is the default setting of the application itself, or the third SDK or The thread-level exception handling logic of the third plug-in will be inherited.
为了避免出现异常,在本实施例中,所述第二异常处理方法的方法名与应用程序的第一异常处理方法的方法名相同的In order to avoid exceptions, in this embodiment, the method name of the second exception handling method is the same as the method name of the first exception handling method of the application program
在本实施例中,第二异常处理方法的至少部分异常处理逻辑是不同于第一异常处理逻辑的。这种不同可以体现在,不用在进行线程级别之间的异常捕获事件的传递等。In this embodiment, at least part of the exception handling logic of the second exception handling method is different from the first exception handling logic. This difference can be reflected in the fact that there is no need to transfer exception capture events between thread levels.
可选地,所述第二异常方法包括:Optionally, the second exception method includes:
继承的所述第一异常处理方法;Inherited said first exception handling method;
创建的第三异常处理方法;其中,所述第三异常处理方法的异常处理逻辑不同于所述第一异常处理方法的异常处理逻辑。A third exception handling method is created; wherein, the exception handling logic of the third exception handling method is different from the exception handling logic of the first exception handling method.
在本实施例中所述第三异常处理方法的异常处理逻辑与所述第一异常处理方法的异常处理逻辑不同。例如,所述第三异常处理逻辑可为异常代码删除逻辑。例如,在通过补丁进行故障(bug)修复的热修复技术中,当前下载的补丁被安装后可能应用程序的其他故障,例如,应用程序无法执行。此时的第三异常处理方法可包括:删除导致异常补丁的异常处理逻辑;如此,就实现了基于补丁的热修复回退功能,应用程序该补丁被删除或被卸载之后,至少能够恢复到应用程序的原始运行状态,减少因热修复技术导致的更大应用程序异常的问题。In this embodiment, the exception handling logic of the third exception handling method is different from the exception handling logic of the first exception handling method. For example, the third exception handling logic may be exception code deletion logic. For example, in a hot repair technology for repairing a bug by using a patch, after the currently downloaded patch is installed, there may be other failures of the application program, for example, the application program cannot be executed. The third exception handling method at this time may include: deleting the exception handling logic that causes the abnormal patch; in this way, the hot fix rollback function based on the patch is realized. After the patch is deleted or uninstalled, the application can at least restore to the application The original running state of the program, reducing the problem of larger application exceptions caused by hot repair technology.
所述第三异常处理方法可为预先设置在所述应用程序中的线程组级别的异常处理方法,也可以是从网络侧的服务器下载的异常处理方法,创建所述第三异常处理方法的方式有多种,不局限于上述方法。The third exception handling method can be an exception handling method preset at the thread group level in the application program, or an exception handling method downloaded from a server on the network side, and the method of creating the third exception handling method There are many methods, not limited to the above methods.
在一些实施例中,所述第二异常方法的异常处理逻辑可以完全不同于所述第一异常处理方法的异常处理逻辑,则此时,所述第二异常处理方法可以是完全重新创建的异常处理逻辑。In some embodiments, the exception handling logic of the second exception handling method may be completely different from the exception handling logic of the first exception handling method, then at this time, the second exception handling method may be a completely recreated exception processing logic.
可选地,所述步骤S120可包括:利用覆写机制在所述第一线程组内创建所述异常处理方法。Optionally, the step S120 may include: using an overriding mechanism to create the exception handling method in the first thread group.
例如,针对java等程序语言,可以采用覆写机制继承应用程序的原始异常处理方法(即所述第一异常处理方法,例如,归属第二线程组内各线程的异常处理方法)等。采用这种覆写机制创建了第一线程组内的异常处理方法,在java程序语言中,就同时存在了子类和父类;第一线程组内创建的异常处理方法,相当于第二线程组内的异常处理方法的子类,子类继承父类的功能或属性之后,父类就不再不执行了,如此就实现了父类的覆盖,从而一方面简便的实现了第一类线程组内异常处理方法的构建,另一方面同时自动屏蔽了第二线程组内的异常处理方法的执行。For example, for programming languages such as java, the original exception handling method of the application program (that is, the first exception handling method, for example, the exception handling method belonging to each thread in the second thread group) can be inherited by using an overwriting mechanism. Using this overriding mechanism to create the exception handling method in the first thread group, in the java programming language, there are both subclasses and parent classes; the exception handling method created in the first thread group is equivalent to the second thread The subclass of the exception handling method in the group, after the subclass inherits the functions or attributes of the parent class, the parent class will no longer be executed, so that the coverage of the parent class is realized, so that the first type of thread group is easily realized on the one hand The construction of the inner exception handling method, on the other hand, automatically shields the execution of the exception handling method in the second thread group.
可选地,所述方法还可包括:Optionally, the method may also include:
根据所述第二线程组的属性设置所述第一线程组的属性;setting the attributes of the first thread group according to the attributes of the second thread group;
根据所述第二线程组的引用设置所述第一线程组的引用。Setting the reference of the first thread group based on the reference of the second thread group.
在本实施例中,由于是利用第一线程组替代所述第二线程组进行异常捕获,故在本实施例中对于操作系统而言,所述第一线程组需要继承第二线程组的属性,才能异常捕获事件从上一级别顺利传递第一线程组,并确保异常捕获的正常进行,故在本实施例中会将第二线程组的属性设置为第一线程组的属性。In this embodiment, since the first thread group is used to replace the second thread group for exception capture, in this embodiment, for the operating system, the first thread group needs to inherit the attributes of the second thread group , the exception capture event can be successfully passed to the first thread group from the upper level, and the normal progress of exception capture can be ensured. Therefore, in this embodiment, the attribute of the second thread group will be set as the attribute of the first thread group.
所述根据所述第二线程组的引用设置所述第一线程组的引用,可包括:将对第二线程组的引用替换为对第一线程组的引用。例如,将对第二线程组的引用替换为对第一线程组的引用,可包括:The setting the reference of the first thread group according to the reference of the second thread group may include: replacing the reference to the second thread group with the reference to the first thread group. For example, to replace references to the second thread group with references to the first thread group, you could include:
将操作系统对第二线程组的引用,替换为第一线程组的引用,如此,可以使得操作系统在发现异常时,将异常捕获事件告知该引用告知第一线程组。The reference of the operating system to the second thread group is replaced with the reference of the first thread group, so that when the operating system finds an exception, it can notify the first thread group of the reference of the exception capture event.
例如,所述将对第二线程组的引用替换为对第一线程组的引用,具体可包括:For example, the replacing the reference to the second thread group with the reference to the first thread group may specifically include:
在一方式中,删除操作系统中对第二线程组的引用关系,并将该应用关系添加第一线程组的线程组标识等参数,从而实现将操作系统对第二线程组的引用修改为对第一线程组的引用关系,如此,操作系统会基于该应用关系在发现异常时,将异常捕获事件告知第一线程组;In one mode, the reference relationship to the second thread group in the operating system is deleted, and parameters such as the thread group identifier of the first thread group are added to the application relationship, thereby realizing that the operating system's reference to the second thread group is modified to be a reference to the second thread group. The reference relationship of the first thread group, so that the operating system will notify the first thread group of the exception capture event when an exception is found based on the application relationship;
在另一些方式中,维持操作系统对第一线程组的应用关系,同时建立操作系统对第一线程组的引用关系,如此也可以确保第一线程组接收到操作系统传输给线程组的异常捕获事件。In other ways, the application relationship of the operating system to the first thread group is maintained, and the reference relationship of the operating system to the first thread group is established at the same time, so that the first thread group can also ensure that the first thread group receives the exception capture transmitted by the operating system to the thread group event.
在一些实施例中,对第二线程组的引用可根据引用的强弱分为:软引用、强引用及弱引用;软引用的引用强度大于强引用的引用强度,强引用的引用强度大于弱引用的引用强度。In some embodiments, the references to the second thread group can be divided into: soft references, strong references, and weak references according to the strength of the references; the reference strength of the soft references is greater than that of the strong references, and the reference strength of the strong references is greater than that of the weak references. The citation strength of the citation.
在一些实施例中,若是软引用或者强引用,则在步骤S120根据第二线程组创建第一线程组时,就会将软引用和/或强引用作为第一线程组的类被创建到第一线程组中。In some embodiments, if it is a soft reference or a strong reference, when the first thread group is created according to the second thread group in step S120, the soft reference and/or strong reference will be created to the second thread group as the class of the first thread group in a thread group.
在另一些实施例中,若第二线程组的引用还包括:若引用,则可能需要进行引用替换,将第二线程组的引用替换为对第一线程组的引用。In some other embodiments, if the reference of the second thread group further includes: if reference, it may be necessary to perform reference replacement, and replace the reference of the second thread group with the reference of the first thread group.
例如,若当前操作系统对第二线程组的引用为弱引用,则还需要将操作系统对第二线程组的引用替换为第一线程组的引用。For example, if the current operating system's reference to the second thread group is a weak reference, it is also necessary to replace the operating system's reference to the second thread group with a reference to the first thread group.
所述第一线程组的异常处理方法可包括:The exception handling method of the first thread group may include:
异常记录方法,该异常记录方法被执行后,会生成异常日志等信息,该异常日志被应用程序的开发商或服务平台,可以通过分析该异常日志定位异常代码,并提供热修复等修复技术;Abnormal recording method, after the abnormal recording method is executed, information such as abnormal logs will be generated. The abnormal log can be analyzed by the developer of the application program or the service platform to locate the abnormal code and provide repair technologies such as hot repair;
异常报告方法,该异常报告方法被执行后,可向服务平台发送异常信息,例如,前述异常日志。通过所述异常报告方法的执行可定期或不定期的向所述服务平台发送所述异常信息。An exception reporting method. After the exception reporting method is executed, exception information, such as the aforementioned exception log, can be sent to the service platform. The abnormality information can be sent to the service platform regularly or irregularly through the execution of the abnormality reporting method.
在一些实施例中,所述异常处理方法还可包括:In some embodiments, the exception handling method may further include:
异常诊断方法,可以用于自动诊断异常的类型、Abnormal diagnosis method, which can be used to automatically diagnose the type of abnormality,
异常定位方法,可以用于定位导致异常的线程和/或代码等。The exception location method can be used to locate the thread and/or code that causes the exception.
以上仅是异常处理方法的举例,具体实现时不局限于上述任意一种。The above are only examples of exception handling methods, and the specific implementation is not limited to any one of the above methods.
可选地,所述根据所述第二线程组的属性设置所述第一线程组的属性,包括以下至少之一:Optionally, the setting the attribute of the first thread group according to the attribute of the second thread group includes at least one of the following:
根据所述第二线程组的线程组名称设置所述第一线程组的线程组名称;Setting the thread group name of the first thread group according to the thread group name of the second thread group;
根据所述第二线程组包括的线程信息设置所述第一线程组包括的线程组信息;Setting the thread group information included in the first thread group according to the thread information included in the second thread group;
根据所述第二线程组的类型设置所述第一线程组的类型,其中,所述类型包括:前台线程组类型和/或后台线程组类型。The type of the first thread group is set according to the type of the second thread group, wherein the type includes: a foreground thread group type and/or a background thread group type.
在本实施例中前台线程组类型:若该类型的线程组运行则设备的前台其运行状态和/或运行结果的线程组,而后台线程组类型的线程组运行,是在设备后台执行的,在前台是看不到其运行状态和/或运行结果的。在前台看到线程组的运行状态和/或运行结果,可显示界面上看到其运行状态和/或运行结果。In this embodiment, the foreground thread group type: if the thread group of this type is running, the thread group of its running status and/or running results in the foreground of the device, and the thread group of the background thread group type is executed in the background of the device. Its running status and/or running results cannot be seen in the foreground. The running status and/or running results of the thread group can be seen in the foreground, and its running status and/or running results can be seen on the display interface.
可选地,所述根据所述第二线程组的属性设置所述第一线程组的属性,包括:Optionally, the setting the attribute of the first thread group according to the attribute of the second thread group includes:
利用反射机制根据所述第二线程组的属性设置所述第一线程组的属性。Using a reflection mechanism to set the attributes of the first thread group according to the attributes of the second thread group.
在本实施例中利用反射机制将第二线程组的属性设置为第一线程组的属性,如此可以不用更改第二线程组的功能。例如,通过反射机制读取到所述第二线程组的属性,并将其赋值给步骤S110中创建的第一线程组,从而使得第一线程组的属相与第二线程组的属性相同。In this embodiment, the reflection mechanism is used to set the attributes of the second thread group to the attributes of the first thread group, so that the functions of the second thread group do not need to be changed. For example, the attribute of the second thread group is read through a reflection mechanism and assigned to the first thread group created in step S110, so that the attribute of the first thread group is the same as the attribute of the second thread group.
例如,java的反射机制可如下:For example, the reflection mechanism of java can be as follows:
java程序在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法和属性;这种动态获取信息以及动态调用对象方法的功能称为java语言的反射机制。In the running state of a java program, for any class, you can know all the properties and methods of this class; for any object, you can call any of its methods and properties; this function of dynamically obtaining information and dynamically calling object methods It is called the reflection mechanism of java language.
故在本实施例中,若第二线程组的属性设置为私有,则获取第二线程组的属性时,可选择在第二线程组在运行过程中去读取其属性,例如,到第二线程组的缓存中读取第二线程组的其属性,从而简便的实现了将第二线程组的属性赋值给第一线程组的目的。Therefore, in this embodiment, if the attribute of the second thread group is set to private, when obtaining the attribute of the second thread group, you can choose to read its attribute during the running of the second thread group, for example, to the second thread group The attributes of the second thread group are read from the cache of the thread group, thereby simply realizing the purpose of assigning the attributes of the second thread group to the first thread group.
可选地,参考图2,所述步骤S130可包括:Optionally, referring to FIG. 2, the step S130 may include:
所述第一线程组从操作系统接收异常捕获事件;The first thread group receives an exception capture event from an operating system;
所述第一线程组的异常捕获方法基于异常捕获事件执行异常捕获。The exception catching method of the first thread group performs exception catching based on an exception catching event.
在本实施例中,会利用第一线程组直接替代第二线程组从操作系统接收异常捕获事件,如此,第一线程组的异常处理功能被激活,在本实施例中第一线程组直接进行线程组级别的异常处理,不再需要在线程级别的线程之间传递异常捕获事件,从而避免因为不同线程之间不传递异常捕获事件导致的异常检测不全面或记录不全面等问题。In this embodiment, the first thread group will be used to directly replace the second thread group to receive exception capture events from the operating system. In this way, the exception handling function of the first thread group is activated. In this embodiment, the first thread group directly performs Exception handling at the thread group level no longer needs to pass exception capture events between threads at the thread level, thereby avoiding problems such as incomplete exception detection or incomplete records caused by not passing exception capture events between different threads.
如图3所示,本实施例提供一种异常检测处理装置,包括:As shown in Figure 3, this embodiment provides an abnormality detection processing device, including:
第一创建模块110,用于创建第一线程组;A first creating module 110, configured to create a first thread group;
第二创建模块120,用于在所述第一线程组内创建异常处理方法;A second creating module 120, configured to create an exception handling method in the first thread group;
替代处理模块130,用于利用所述第一线程组替代应用程序的第二线程组进行异常处理。The replacement processing module 130 is configured to use the first thread group to replace the second thread group of the application program to perform exception handling.
在本实施例中,所述第一创建模块110、第二创建模块120、替代模块及处理模块均可为程序模块,可以用于创建所述第一线程组、创建异常处理方法、并替代第二线程组进行异常处理等。In this embodiment, the first creating module 110, the second creating module 120, the replacement module and the processing module can all be program modules, which can be used to create the first thread group, create an exception handling method, and replace the first thread group. The second thread group performs exception handling and so on.
可选地,所述第二创建模块120,具体用于在所述第一线程组内创建第二异常处理方法;将所述应用程序的第一异常处理方法的方法名设置为所述第二异常处理方法的方法名;其中,所述第二异常处理方法的异常处理逻辑,至少部分不同于所述第一异常处理方法的异常处理逻辑。Optionally, the second creation module 120 is specifically configured to create a second exception handling method in the first thread group; set the method name of the first exception handling method of the application as the second The method name of the exception handling method; wherein, the exception handling logic of the second exception handling method is at least partially different from the exception handling logic of the first exception handling method.
可选地,所述第二异常方法包括:继承的所述第一异常处理方法;和/或,创建的第三异常处理方法;其中,所述第三异常处理方法的异常处理逻辑不同于所述第一异常处理方法的异常处理逻辑。Optionally, the second exception handling method includes: the inherited first exception handling method; and/or, a created third exception handling method; wherein, the exception handling logic of the third exception handling method is different from the Describe the exception handling logic of the first exception handling method.
可选地,所述第二创建模块120,具体用于利用覆写机制在所述第一线程组内创建所述异常处理方法。Optionally, the second creating module 120 is specifically configured to create the exception handling method in the first thread group by using an overwriting mechanism.
可选地,所述装置还包括:Optionally, the device also includes:
属性模块,具体用于根据所述第二线程组的属性设置所述第一线程组的属性;An attribute module, specifically configured to set the attribute of the first thread group according to the attribute of the second thread group;
引用替换模块,用于根据所述第二线程组的引用设置所述第一线程组的引用。A reference replacement module, configured to set the reference of the first thread group according to the reference of the second thread group.
可选地,所述第二创建模块120,具体可用于执行以下至少之一:Optionally, the second creation module 120 may be specifically configured to perform at least one of the following:
根据所述第二线程组的线程组名称设置所述第一线程组的线程组名称;Setting the thread group name of the first thread group according to the thread group name of the second thread group;
根据所述第二线程组包括的线程信息设置所述第一线程组包括的线程组信息;Setting the thread group information included in the first thread group according to the thread information included in the second thread group;
根据所述第二线程组的类型设置所述第一线程组的类型,其中,所述类型包括:前台线程组类型和/或后台线程组类型。The type of the first thread group is set according to the type of the second thread group, wherein the type includes: a foreground thread group type and/or a background thread group type.
在另一些实施例中,所述第二创建模块120,具体可用于利用反射机制根据所述第二线程组的属性设置所述第一线程组的属性。In some other embodiments, the second creating module 120 may be specifically configured to use a reflection mechanism to set the attribute of the first thread group according to the attribute of the second thread group.
在一些实施例中,所述替代处理模块130,具体可用于所述第一线程组从操作系统接收异常捕获事件;所述第一线程组的异常捕获方法基于异常捕获事件执行异常捕获。In some embodiments, the alternative processing module 130 may be specifically configured for the first thread group to receive an exception capture event from an operating system; the exception capture method of the first thread group executes exception capture based on the exception capture event.
本实施例提供一种电子设备,包括:This embodiment provides an electronic device, including:
存储器,用于信息存储;memory for information storage;
处理器,与所述存储器连接,用于通过执行存储在所述存储器上的计算机可执行指令,实现前述一个或多个技术方案提供的方法。A processor, connected to the memory, configured to implement the method provided by the foregoing one or more technical solutions by executing computer-executable instructions stored in the memory.
存储器可以是易失性存储器或非易失性存储器,也可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read Only Memory,ROM)、可编程只读存储器(Programmable Read-Only Memory,PROM)、可擦除可编程只读存储器(ErasableProgrammable Read-Only Memory,EPROM)、电可擦除可编程只读存储器(ElectricallyErasable Programmable Read-Only Memory,EEPROM)、磁性随机存取存储器(ferromagnetic random access memory,FRAM)、快闪存储器(Flash Memory)、磁表面存储器、光盘、或只读光盘(CD-ROM,Compact Disc Read-Only Memory);磁表面存储器可以是磁盘存储器或磁带存储器。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(Static Random Access Memory,SRAM)、同步静态随机存取存储器(Synchronous Static Random Access Memory,SSRAM)、动态随机存取存储器(DynamicRandom Access Memory,DRAM)、同步动态随机存取存储器(Synchronous Dynamic RandomAccess Memory,SDRAM)、双倍数据速率同步动态随机存取存储器(Double Data RateSynchronous Dynamic Random Access Memory,DDRSDRAM)、增强型同步动态随机存取存储器(Enhanced Synchronous Dynamic Random Access Memory,ESDRAM)、同步连接动态随机存取存储器(SyncLink Dynamic Random Access Memory,SLDRAM)、直接内存总线随机存取存储器(Direct Rambus Random Access Memory,DRRAM)。本发明实施例描述的存储器旨在包括但不限于这些和任意其它适合类型的存储器。Memory can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. Wherein, the nonvolatile memory can be a read-only memory (Read Only Memory, ROM), a programmable read-only memory (Programmable Read-Only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Magnetic Random Access Memory (FRAM), Flash Memory (Flash Memory), Magnetic Surface Memory, Optical Disk , or CD-ROM (Compact Disc Read-Only Memory); the magnetic surface storage can be disk storage or tape storage. The volatile memory can be Random Access Memory (RAM), which acts as an external cache. By way of illustration and not limitation, many forms of RAM are available such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory Memory (Dynamic Random Access Memory, DRAM), Synchronous Dynamic Random Access Memory (Synchronous Dynamic Random Access Memory, SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (Double Data Rate Synchronous Dynamic Random Access Memory, DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced Synchronous Dynamic Random Access Memory, ESDRAM), Synchronous Connection Dynamic Random Access Memory (SyncLink Dynamic Random Access Memory, SLDRAM), Direct Memory Bus Random Access Memory (Direct Rambus Random Access Memory, DRRAM). The memory described by embodiments of the present invention is intended to include, but not be limited to, these and any other suitable types of memory.
所述处理器可为中央处理器、微处理器、数字信号处理器、可编程阵列或专用集成电路等。The processor can be a central processing unit, a microprocessor, a digital signal processor, a programmable array or an application-specific integrated circuit, and the like.
在一些实施例中,所述电子设备还可包括通信接口,该通信接口可与处理器连接,该通信接口可包括:与外围设备连接外设设备接口或网络进行连接的网络接口。通信接口为处理器与外围接口模块之间的信息交互提供接口,上述外围接口模块可以是键盘、鼠标、轨迹球、点击轮、按键、按钮等。这些按钮可包括但不限于:主页按钮、音量按钮、启动按钮和锁定按钮。In some embodiments, the electronic device may further include a communication interface, which may be connected to the processor, and the communication interface may include: a network interface for connecting peripheral devices to a peripheral device interface or a network. The communication interface provides an interface for information exchange between the processor and the peripheral interface module. The peripheral interface module may be a keyboard, mouse, trackball, click wheel, key, button, etc. These buttons may include, but are not limited to: a home button, volume buttons, start button, and lock button.
处理器可以通过集成电路总线等电子设备内的总线接口与存储器或通信接口等连接。The processor can be connected to a memory or a communication interface through a bus interface in an electronic device such as an integrated circuit bus.
本实施例提供的电子设备可为手机、平板电脑、可穿戴式设备、虚拟现实设备或增强现实设备等各种移动设备或固定设备。The electronic device provided in this embodiment may be various mobile or fixed devices such as a mobile phone, a tablet computer, a wearable device, a virtual reality device or an augmented reality device.
本实施例还提供一种计算机存储介质,所述计算机存储介质存储有计算机可执行指令;所述计算机可执行指令被执行后能够前述任意一个实施例提供的方法,例如,图1和/或图4所示的方法。This embodiment also provides a computer storage medium, the computer storage medium stores computer-executable instructions; after the computer-executable instructions are executed, the method provided by any one of the foregoing embodiments can be performed, for example, FIG. 1 and/or FIG. 4 shows the method.
该计算机存储介质可为光盘、移动硬盘、软盘、U盘、随机存储器、只读存储器等各种存储介质,可选为非瞬间存储介质。The computer storage medium can be various storage mediums such as optical discs, mobile hard disks, floppy disks, U disks, random access memories, read-only memories, etc., and can be selected as non-transient storage media.
以下结合上述任意实施例提供几个具体示例:Several specific examples are provided below in combination with any of the above-mentioned embodiments:
示例1:Example 1:
如图4所示,本示例提供一种应用程序的异常检测方法,可包括:As shown in Figure 4, this example provides an anomaly detection method for an application, which may include:
应用程序启动时,创建第一线程组,该新建立的第一线程组可与应用程序的主函数所在的主线程组的类型相同等;When the application starts, a first thread group is created, and the newly established first thread group may be of the same type as the main thread group where the main function of the application is located;
利用覆写机制在第一线程组内创建第一异常处理方法;例如,覆写主线程组的异常处理方法,获得所述第一异常处理方法;Create a first exception handling method in the first thread group by using the override mechanism; for example, override the exception handling method of the main thread group to obtain the first exception handling method;
在第一线程组内添加预先设定的第三异常处理方法,或从网络服务器下载第三异常处理方法;Adding a preset third exception handling method in the first thread group, or downloading the third exception handling method from the network server;
利用反射机制根据第二线程组的属性设置第一线程组的属性;Using a reflection mechanism to set the attributes of the first thread group according to the attributes of the second thread group;
利用第二线程组监控操作系统(例如,系统线程组)提供的异常捕获事件,并在监控到异常捕获事件时,进行线程组级别的异常捕获等异常处理。Utilize the second thread group to monitor the exception capture event provided by the operating system (for example, the system thread group), and perform exception handling such as thread group level exception capture when the exception capture event is monitored.
示例2:Example 2:
本示例先提供几个相关术语的描述,具体如下:This example first provides descriptions of several related terms, as follows:
线程组包括:多个线程,可以统一对其中的线程进行统一管理。The thread group includes: a plurality of threads, and the threads in it can be uniformly managed.
在java的多线程处理中有线程组(ThreadGroup)的概念,ThreadGroup是为了方便线程管理,可以统一设定线程组的一些属性,比如,属性(setDaemon),设置未处理异常的处理方法,设置统一的安全策略等等;也可以通过线程组方便的获得线程的一些信息。There is a concept of thread group (ThreadGroup) in the multi-thread processing of java. ThreadGroup is to facilitate thread management, and some attributes of the thread group can be set uniformly, for example, attribute (setDaemon), set the processing method of unhandled exception, and set uniform Security policies, etc.; You can also easily obtain some information about the thread through the thread group.
每一个ThreadGroup都可以包含一组的子线程和一组子线程组,在一个进程中线程组是以树形的方式存在,通常情况下根线程组是system线程组。系统(system)线程组下是主(main)线程组,默认情况下第一级应用自己的线程组是通过main线程组创建出来的。系统线程组可以将异常捕获事件告知主线程组,此处的主线程组可为前述的第二线程组。Each ThreadGroup can contain a group of sub-threads and a group of sub-thread groups. In a process, the thread group exists in a tree form. Usually, the root thread group is the system thread group. Under the system (system) thread group is the main (main) thread group. By default, the first-level application's own thread group is created through the main thread group. The system thread group may notify the main thread group of the exception capture event, where the main thread group may be the aforementioned second thread group.
java反射机制:Java reflection mechanism:
java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法和属性;这种动态获取信息以及动态调用对象方法的功能称为java语言的反射机制。The java reflection mechanism is in the running state. For any class, you can know all the properties and methods of this class; for any object, you can call any of its methods and properties; this dynamic acquisition of information and dynamic calling of object methods The function is called the reflection mechanism of the java language.
JAVA反射机制可为:在程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言。反射机制,可为用在java身上指的是我们可以于运行时加载、探知、使用编译期间完全未知的类(classes)。换句话说,java程序可以加载一个运行时才得知名称的类(class),获悉其完整构造(但不包括方法定义),并生成其对象实体、或对其域(fields)设值、或唤起其方法。The JAVA reflection mechanism can be: when the program is running, it is allowed to change the program structure or variable type. This language is called a dynamic language. The reflection mechanism, which can be used in java, means that we can load, detect, and use classes that are completely unknown during compilation at runtime. In other words, a java program can load a class (class) whose name is known at runtime, learn its complete structure (but not including method definitions), and generate its object entity, or set values for its fields (fields), or invoke its method.
1、创建新的线程组,即前述的第一线程组;1. Create a new thread group, namely the aforementioned first thread group;
在应用程序启动后,创建一个新的线程组(ThreadGroup)对象,并覆写该对象所属类中的默认异常捕获方法,在异常捕获方法中实现具体的异常处理逻辑。After the application starts, create a new thread group (ThreadGroup) object, and override the default exception capture method in the class to which the object belongs, and implement specific exception handling logic in the exception capture method.
java提供了ThreadGroup类来控制一个线程组。一个线程组可以通过线程对象来创建,也可以由其他线程组来创建,生成一个树形结构的线程。Java provides the ThreadGroup class to control a thread group. A thread group can be created through a thread object, or it can be created by other thread groups to generate a tree structure of threads.
在创建新的线程组后,通过java的覆写机制(override),将原异常捕获方法覆写为具有自定义逻辑的方法。在进行覆写时,java应用程序会新建一个类,去继承默认异常捕获方法(对应于前述第一异常处理方法)的类,然后在新建的类中实现自定义逻辑方法(对应于前述第三异常处理方法),方法名字跟原来的默认异常捕获方法相同。After creating a new thread group, the original exception catching method is overwritten to a method with custom logic through the java overriding mechanism (override). When overriding, the java application will create a new class to inherit the default exception capture method (corresponding to the aforementioned first exception handling method), and then implement the custom logic method (corresponding to the aforementioned third exception handling method) in the newly created class Exception handling method), the method name is the same as the original default exception catching method.
在安卓系统中,会根据方法名来调用方法,在原有的处理逻辑中,当线程出现异常后,会通过方法名调用线程组中的异常捕获方法来进行异常处理,本提案中,由于将默认异常捕获方法覆写为自定义逻辑的方法,因此在出现异常逻辑后,会根据方法名,调用自定义逻辑的方法,来进行异常处理。In the Android system, the method will be called according to the method name. In the original processing logic, when an exception occurs in the thread, the exception handling method in the thread group will be called through the method name to handle the exception. In this proposal, since the default The exception catching method is overwritten with a custom logic method, so after the exception logic occurs, the method of the custom logic will be called according to the method name to handle the exception.
此处,以热修复回退为例:对热修复功能的回退处理方法(在对应用程序进行热修复后,如果修复后的程序在运行时会崩溃,那么通过本方法,在应用程序异常后,会调用对热修复功能的回退处理方法,对热修复补丁进行卸载,以保证应用程序的正常运行。这样可以在线程组捕获热修复过程中出现的异常后,对热修复功能进行回退处理)。Here, take the hot fix rollback as an example: the rollback processing method for the hot fix function (after the hot fix is performed on the application, if the repaired program will crash during operation, then through this method, when the application is abnormal After that, the rollback processing method for the hot repair function will be called to uninstall the hot repair patch to ensure the normal operation of the application. In this way, the hot repair function can be rolled back after the thread group captures the exception that occurs during the hot repair process. refund processing).
在一些情况下,所述异常处理方法还可包括:将异常信息以日志的形式保存的方法;和/或,将异常信息上传至服务器平台的方法。In some cases, the exception handling method may further include: a method of saving the exception information in the form of a log; and/or a method of uploading the exception information to the server platform.
线程组属性的复用Reuse of thread group attributes
通过java反射机制来获取APP主线程所在的主线程组对象,为了不影响主线程所在线程组的原有功能(在java中,线程组和现场之间的交互是根据线程组属性来进行的,如果不复用原有线程组属性,将导致主线程所属线程组的名称发生变化,以及原有线程组包含的其他线程丢失等等,导致应用程序运行异常),通过安卓反射功能,获取主线程所属线程组的所有属性,并将获取的属性赋值给新建的线程组对象,从而实现复用主线程的线程组信息。该线程组信息比如可以是:线程组名称、线程组包含的线程信息、是否为后台程序线程组等。Use the java reflection mechanism to obtain the main thread group object where the APP main thread is located. In order not to affect the original function of the thread group where the main thread is located (in java, the interaction between the thread group and the scene is based on the thread group attributes. If the original thread group attribute is not reused, the name of the thread group to which the main thread belongs will change, and other threads contained in the original thread group will be lost, etc., resulting in abnormal operation of the application), and the main thread can be obtained through the Android reflection function All attributes of the thread group to which it belongs, and assign the obtained attributes to the newly created thread group object, so as to realize the reuse of the thread group information of the main thread. The thread group information may be, for example: a thread group name, thread information included in the thread group, whether it is a background program thread group, and the like.
线程组替换,包括:以安卓系统为例进行说明,由于安卓将线程的线程组属性设置为私有,因此无法通过正常途径获取主线程的线程组对象,将APP主线程的线程组,通过安卓反射功能,获取主线程的线程组引用后,将其指向为已复用原线程组信息的新线程组,从而实现主线程的线程组替换,从而使新线程组中具备自定义逻辑的方法(比如,处理热修复异常回退逻辑的异常处理方法),实现异常捕获能力。Thread group replacement, including: Taking the Android system as an example, because Android sets the thread group attribute of the thread as private, it is impossible to obtain the thread group object of the main thread through the normal way, and the thread group of the APP main thread is reflected by Android Function, after obtaining the thread group reference of the main thread, point it to a new thread group that has reused the information of the original thread group, so as to realize the replacement of the thread group of the main thread, so that the new thread group has a method with custom logic (such as , the exception handling method that handles the hotfix exception rollback logic), and realizes the ability to catch exceptions.
崩溃异常捕获及处理,包括:当APP发生崩溃事件后,异常信息首先会Crash exception capture and processing, including: when an APP crash event occurs, the exception information will first
传递至发生崩溃的线程所在的线程组,本方案通过将主线程原来只有默Passed to the thread group where the crashed thread is located, this solution uses only the default
认异常处理逻辑的线程组对象,替换为具有实际需要的异常处理逻辑的The thread group object that recognizes the exception handling logic is replaced by the thread group object that has the exception handling logic actually needed
线程组对象,进行异常事件捕获,并将异常信息上报至异常管理平台。The thread group object captures abnormal events and reports the abnormal information to the abnormal management platform.
通过本提案的方法,除了能捕获主线程的异常外,能否通过类似的方法捕获应用程序其它线程的异常,只要通过本方法替换待捕获异常的线程所属的线程组即可。Through the method of this proposal, in addition to catching the exception of the main thread, whether the exception of other threads of the application can be caught through a similar method, as long as the thread group to which the thread to be caught is replaced by this method.
异常捕获事件传递第一层级是线程组级别的异常捕获,第二层级是线程级别的异常捕获,异常的传递是从第一层传递至第二层。目前通用的异常捕获方案都是针对第二层级,如果有一个异常捕获程序在第二层级进行异常捕获,且捕获异常后,不将异常传递给其他异常捕获程序,那其他异常处理程序将无法捕获异常,而本方案的异常捕获机制是第一层级,在第一层级即可完成异常捕获,并且也可将异常捕获传递给第二层级,此时如果有异常程序在第二层级进行异常捕获且不进行异常传递,也不影响本方案的异常捕获。The first level of exception capture event transmission is the exception capture at the thread group level, the second level is the thread level exception capture, and the exception transmission is from the first level to the second level. The current common exception capture schemes are all aimed at the second level. If there is an exception capture program that captures exceptions at the second level and does not pass the exception to other exception capture programs after catching the exception, then other exception handlers will not be able to catch it. exception, and the exception capture mechanism of this scheme is the first level, the exception capture can be completed at the first level, and the exception capture can also be passed to the second level, at this time, if there is an abnormal program at the second level, the exception capture and No exception transmission is performed, nor does it affect the exception capture of this solution.
通过将线程的线程组替换为自定义的具有异常捕获及处理逻辑的线程组,来实现异常捕获。不存在相关异常捕获方案中存在的异常捕获被互相覆盖的情况。Exception capture is achieved by replacing the thread group of threads with a custom thread group with exception capture and processing logic. There is no situation where exception captures that exist in related exception capture schemes are overridden by each other.
在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。In the several embodiments provided in this application, it should be understood that the disclosed devices and methods may be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or May be integrated into another system, or some features may be ignored, or not implemented. In addition, the coupling, or direct coupling, or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms of.
上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units; Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本发明各实施例中的各功能单元可以全部集成在一个处理模块中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention can be integrated into one processing module, or each unit can be used as a single unit, or two or more units can be integrated into one unit; the above-mentioned integration The unit can be realized in the form of hardware or in the form of hardware plus software functional unit.
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps for realizing the above-mentioned method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the Including the steps of the foregoing method embodiments; and the aforementioned storage medium includes: various storage devices, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk A medium on which program code can be stored.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.
在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。In the several embodiments provided in this application, it should be understood that the disclosed devices and methods may be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or May be integrated into another system, or some features may be ignored, or not implemented. In addition, the coupling, or direct coupling, or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms of.
上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units; Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本发明各实施例中的各功能单元可以全部集成在一个处理模块中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention can be integrated into one processing module, or each unit can be used as a single unit, or two or more units can be integrated into one unit; the above-mentioned integration The unit can be realized in the form of hardware or in the form of hardware plus software functional unit.
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps for realizing the above-mentioned method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the Including the steps of the foregoing method embodiments; and the aforementioned storage medium includes: various storage devices, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk A medium on which program code can be stored.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810381722.4A CN108563581A (en) | 2018-04-25 | 2018-04-25 | Abnormality detection processing method and apparatus, electronic device, and computer storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810381722.4A CN108563581A (en) | 2018-04-25 | 2018-04-25 | Abnormality detection processing method and apparatus, electronic device, and computer storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN108563581A true CN108563581A (en) | 2018-09-21 |
Family
ID=63536766
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201810381722.4A Pending CN108563581A (en) | 2018-04-25 | 2018-04-25 | Abnormality detection processing method and apparatus, electronic device, and computer storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN108563581A (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110175101A (en) * | 2019-04-30 | 2019-08-27 | 北京百度网讯科技有限公司 | A kind of exception catching method, apparatus and terminal |
| CN111290872A (en) * | 2020-01-15 | 2020-06-16 | 上海高仙自动化科技发展有限公司 | Application program and exception handling method for application program |
| CN111639004A (en) * | 2020-05-12 | 2020-09-08 | 腾讯音乐娱乐科技(深圳)有限公司 | User interface card pause monitoring method and device and storage medium |
| CN112988554A (en) * | 2019-12-12 | 2021-06-18 | 阿里巴巴集团控股有限公司 | SDK detection method, device, SDK, application program, device and storage medium |
| CN113419919A (en) * | 2021-06-24 | 2021-09-21 | 亿览在线网络技术(北京)有限公司 | Method for thread monitoring of third-party SDK |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101639803A (en) * | 2008-07-30 | 2010-02-03 | 株式会社日立制作所 | Exception handling method and exception handling device for multithread application system |
| WO2015136283A1 (en) * | 2014-03-14 | 2015-09-17 | Arm Limited | Exception handling in microprocessor systems |
| CN105653455A (en) * | 2015-12-29 | 2016-06-08 | 广东欧珀移动通信有限公司 | Program vulnerability detection method and detection system |
| CN106485141A (en) * | 2016-10-21 | 2017-03-08 | 天津海量信息技术股份有限公司 | The detection of abnormal traffic thread and processing method under JAVA environment |
-
2018
- 2018-04-25 CN CN201810381722.4A patent/CN108563581A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101639803A (en) * | 2008-07-30 | 2010-02-03 | 株式会社日立制作所 | Exception handling method and exception handling device for multithread application system |
| WO2015136283A1 (en) * | 2014-03-14 | 2015-09-17 | Arm Limited | Exception handling in microprocessor systems |
| CN106104483A (en) * | 2014-03-14 | 2016-11-09 | Arm有限公司 | Abnormality processing in microprocessor system |
| CN105653455A (en) * | 2015-12-29 | 2016-06-08 | 广东欧珀移动通信有限公司 | Program vulnerability detection method and detection system |
| CN106485141A (en) * | 2016-10-21 | 2017-03-08 | 天津海量信息技术股份有限公司 | The detection of abnormal traffic thread and processing method under JAVA environment |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110175101A (en) * | 2019-04-30 | 2019-08-27 | 北京百度网讯科技有限公司 | A kind of exception catching method, apparatus and terminal |
| CN110175101B (en) * | 2019-04-30 | 2023-05-26 | 北京百度网讯科技有限公司 | Abnormality capturing method and device and terminal |
| CN112988554A (en) * | 2019-12-12 | 2021-06-18 | 阿里巴巴集团控股有限公司 | SDK detection method, device, SDK, application program, device and storage medium |
| CN112988554B (en) * | 2019-12-12 | 2024-05-17 | 阿里巴巴集团控股有限公司 | SDK detection method, device, SDK program, device, and storage medium |
| CN111290872A (en) * | 2020-01-15 | 2020-06-16 | 上海高仙自动化科技发展有限公司 | Application program and exception handling method for application program |
| CN111639004A (en) * | 2020-05-12 | 2020-09-08 | 腾讯音乐娱乐科技(深圳)有限公司 | User interface card pause monitoring method and device and storage medium |
| CN113419919A (en) * | 2021-06-24 | 2021-09-21 | 亿览在线网络技术(北京)有限公司 | Method for thread monitoring of third-party SDK |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11169902B2 (en) | Techniques for evaluating collected build metrics during a software build process | |
| US10296437B2 (en) | Framework for efficient security coverage of mobile software applications | |
| US10181029B1 (en) | Security cloud service framework for hardening in the field code of mobile software applications | |
| US7908521B2 (en) | Process reflection | |
| US9594905B1 (en) | Framework for efficient security coverage of mobile software applications using machine learning | |
| CN108563581A (en) | Abnormality detection processing method and apparatus, electronic device, and computer storage medium | |
| US9223681B2 (en) | Automated debug trace specification | |
| CN105183457B (en) | Method and device for monitoring interface life cycle callback | |
| US8745598B2 (en) | Running injected code prior to execution of an application | |
| US20150006961A1 (en) | Capturing trace information using annotated trace output | |
| Saltaformaggio et al. | Screen after Previous Screens:{Spatial-Temporal} Recreation of Android App Displays from Memory Images | |
| CN106095689A (en) | The detection method of a kind of application memory leakage and device | |
| CN106951371B (en) | A kind of semi-automatic test method of Android application based on dependence injection | |
| CN105912366A (en) | Implementation method for plug-in type development of desktop application | |
| CN105915546A (en) | Traffic monitoring method and device of android application | |
| KR101974989B1 (en) | Method and apparatus for determining behavior information corresponding to a dangerous file | |
| CN114184885A (en) | Fault detection method, device and storage medium | |
| JP2004094374A (en) | Logging system | |
| US20180203787A1 (en) | Detection of software errors | |
| CN110837465A (en) | Android-based handle leakage detection method and system | |
| US20230418729A1 (en) | Debugging operator errors in a distributed computing environment | |
| CN116382959A (en) | Abnormal dump processing method of operating system and vehicle control equipment | |
| CN110046004B (en) | Method and device for adapting automatic reference counting ARC (ARC resistance) characteristics and electronic equipment | |
| CN113031964A (en) | Management method, device, equipment and storage medium for big data application | |
| CN117453513B (en) | Log acquisition method and related equipment |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20180921 |
|
| RJ01 | Rejection of invention patent application after publication |