CN107818023B - Thread-based message processing method, intelligent device and storage medium - Google Patents

Thread-based message processing method, intelligent device and storage medium Download PDF

Info

Publication number
CN107818023B
CN107818023B CN201711082986.1A CN201711082986A CN107818023B CN 107818023 B CN107818023 B CN 107818023B CN 201711082986 A CN201711082986 A CN 201711082986A CN 107818023 B CN107818023 B CN 107818023B
Authority
CN
China
Prior art keywords
thread
target
function
receiving function
type
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.)
Active
Application number
CN201711082986.1A
Other languages
Chinese (zh)
Other versions
CN107818023A (en
Inventor
卢伟超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen leynew Network Media Co Ltd
Original Assignee
Shenzhen Leiniao Network Media Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Leiniao Network Media Co ltd filed Critical Shenzhen Leiniao Network Media Co ltd
Priority to CN201711082986.1A priority Critical patent/CN107818023B/en
Publication of CN107818023A publication Critical patent/CN107818023A/en
Application granted granted Critical
Publication of CN107818023B publication Critical patent/CN107818023B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Abstract

The invention discloses a message processing method based on threads, intelligent equipment and a storage medium. When the intelligent equipment detects a sending function, the intelligent equipment acquires the target thread type of the sending function, searches a receiving function corresponding to the target thread type in a current receiving function set, takes the searched receiving function as a target receiving function, and distributes messages in the target thread where the target receiving function is located through the target receiving function. The method and the device realize the determination of different executable receiving functions based on different sending functions, and overcome the technical problem that the better coupling between the sending functions and the receiving functions cannot be ensured in the Android system.

Description

Thread-based message processing method, intelligent device and storage medium
Technical Field
The invention relates to the field of Android systems, in particular to a message processing method based on threads, intelligent equipment and a storage medium.
Background
With the continuous development and application of the Android system, a message processing mechanism of the Android system is used as a main implementation principle for sending and receiving messages in the Android system, and plays a key role in the operation of the Android system. However, with the progressive application of the Android system, in the development link of the system or the application program, in order to better implement specific functions, various internal classes may appear in the program of the developer, and various communication interfaces are implemented, so that the coupling between the sender and the receiver is reduced.
For example, an anonymous subclass Handler may be implemented below a function in the code, which may cause that the function of the sender and the function of the receiver do not have good coupling, so that the current Android system cannot ensure that the sending function and the receiving function maintain good coupling in the process of message processing, and therefore, the current Android system has a technical problem that the sending function and the receiving function cannot ensure that the sending function and the receiving function maintain good coupling.
The above is only for the purpose of assisting understanding of the technical aspects of the present invention, and does not represent an admission that the above is prior art.
Disclosure of Invention
The invention mainly aims to provide a message processing method based on a thread, intelligent equipment and a storage medium, and aims to solve the technical problem that the Android system in the prior art cannot ensure that a sending function and a receiving function are kept good in coupling.
In order to achieve the above object, the present invention provides a message processing method based on threads, which comprises the following steps:
the method comprises the steps that when the intelligent equipment detects a sending function, the target thread type of the sending function is obtained;
searching a receiving function corresponding to the target thread type in the current receiving function set, and taking the searched receiving function as a target receiving function;
and performing message distribution in a target thread where the target receiving function is located through the target receiving function.
Preferably, after the intelligent device acquires the target thread type of the sending function when the intelligent device detects the sending function, the thread-based message processing method further includes:
acquiring the target function parameter type of the sending function;
and finding a corresponding current receiving function set according to the target function parameter type in a mapping relation, wherein the mapping relation comprises the corresponding relation between the function parameter type and the receiving function set, and the receiving function set comprises all receiving functions.
Preferably, before the intelligent device acquires the type of the target function parameter of the sending function when the intelligent device detects the sending function, the method for processing the message based on the thread further includes:
acquiring corresponding sample receiving functions according to a preset class object based on a Java reflection mechanism;
determining a corresponding sample function parameter type according to the sample receiving function;
and taking each sample receiving function with the same sample function parameter type as a sample receiving function set, establishing a corresponding relation between the sample function parameter type and the sample receiving function set, and adding the corresponding relation into the mapping relation.
Preferably, before the Java-based reflection mechanism obtains the corresponding sample receiving functions according to the preset class objects, the thread-based message processing method further includes:
acquiring the reference information of the sending function;
and generating the preset class object according to the reference information.
Preferably, the reference information is class type information;
correspondingly, the generating the preset class object according to the reference information and acquiring corresponding sample receiving functions according to the preset class object based on a reflection mechanism of Java specifically includes:
generating a class object according to the class information;
and acquiring corresponding sample receiving functions according to the class objects based on a Java reflection mechanism.
Preferably, the distributing the message in the target thread where the target receiving function is located through the target receiving function specifically includes:
identifying the target thread type;
when the target thread type is a main thread type, distributing messages in the main thread through the target receiving function, wherein the main thread type corresponds to the main thread;
or the like, or, alternatively,
and when the target thread type is a sub-thread type, distributing the message in the sub-thread through the target receiving function, wherein the sub-thread type corresponds to the sub-thread.
Preferably, when the target thread type is a main thread type, the message distribution in the main thread is performed through the target receiving function, which specifically includes:
and when the target thread type is a main thread type, calling a Looper of the main thread through the target receiving function so as to enable the target receiving function to distribute the message in the main thread.
Preferably, when the target thread type is a child thread type, the message distribution in the child thread is performed through the target receiving function, which specifically includes:
and when the target thread type is the sub-thread type, creating a new thread and calling a Looper of the new thread so as to enable the target receiving function to distribute the message in the new thread.
In addition, to achieve the above object, the present invention also provides an intelligent device, including: a memory, a processor, and a thread-based message handler stored on the memory and operable on the processor, the thread-based message handler configured to implement the steps of the thread-based message handling method as described above.
Furthermore, to achieve the above object, the present invention also provides a storage medium having stored thereon a thread-based message processing program, which when executed by a processor implements the steps of the thread-based message processing method as described above.
According to the method and the device, the receiving function corresponding to the target thread type is found, the found receiving function is used as the target receiving function, and the message is distributed in the target thread through the target receiving function, so that different executable receiving functions are determined based on different sending functions, and the technical problem that the better coupling between the sending function and the receiving function cannot be guaranteed in an Android system is solved.
Drawings
FIG. 1 is a schematic diagram of an intelligent device architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a method for thread-based message processing according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of a thread-based message processing method according to the present invention;
FIG. 4 is a flowchart illustrating a third embodiment of a thread-based message processing method according to the present invention;
FIG. 5 is a flowchart illustrating a fourth embodiment of a method for processing a message based on threads according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of an intelligent device in a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the smart device may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), and the optional user interface 1003 may further include a standard wired interface and a wireless interface, and the wired interface for the user interface 1003 may be a USB interface in the present invention. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
The intelligent device can be an electronic device such as an Android system-based intelligent mobile phone and a tablet personal computer.
Those skilled in the art will appreciate that the architecture shown in fig. 1 does not constitute a limitation of smart devices and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, the memory 1005, which is a type of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a thread-based message handler.
In the intelligent device shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server and performing data communication with the background server; the user interface 1003 is mainly used for connecting peripheral equipment; the smart device invokes, via the processor 1001, a thread-based message handler stored in the memory 1005, and performs the following operations:
when a sending function is detected, acquiring a target thread type of the sending function;
searching a receiving function corresponding to the target thread type in the current receiving function set, and taking the searched receiving function as a target receiving function;
and performing message distribution in a target thread where the target receiving function is located through the target receiving function.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
acquiring the target function parameter type of the sending function;
and finding a corresponding current receiving function set according to the target function parameter type in a mapping relation, wherein the mapping relation comprises the corresponding relation between the function parameter type and the receiving function set, and the receiving function set comprises all receiving functions.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
acquiring corresponding sample receiving functions according to a preset class object based on a Java reflection mechanism;
determining a corresponding sample function parameter type according to the sample receiving function;
and taking each sample receiving function with the same sample function parameter type as a sample receiving function set, establishing a corresponding relation between the sample function parameter type and the sample receiving function set, and adding the corresponding relation into the mapping relation.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
acquiring the reference information of the sending function;
and generating the preset class object according to the reference information.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
generating a class object according to the class information;
and acquiring corresponding sample receiving functions according to the class objects based on a Java reflection mechanism.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
identifying the target thread type;
when the target thread type is a main thread type, distributing messages in the main thread through the target receiving function, wherein the main thread type corresponds to the main thread;
or the like, or, alternatively,
and when the target thread type is a sub-thread type, distributing the message in the sub-thread through the target receiving function, wherein the sub-thread type corresponds to the sub-thread.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
and when the target thread type is a main thread type, calling a Looper of the main thread through the target receiving function so as to enable the target receiving function to distribute the message in the main thread.
Further, the processor 1001 may call a thread-based message handler stored in the memory 1005, and also perform the following operations:
and when the target thread type is the sub-thread type, creating a new thread and calling a Looper of the new thread so as to enable the target receiving function to distribute the message in the new thread.
In this embodiment, by finding the receiving function corresponding to the target thread type, taking the found receiving function as a target receiving function, and performing message distribution in the target thread through the target receiving function, different executable receiving functions are determined based on different sending functions, and a technical problem that a better coupling property between the sending function and the receiving function cannot be ensured in an Android system is solved.
Based on the above hardware structure, an embodiment of the message processing method based on threads is provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of a method for processing a message based on a thread according to the present invention.
In a first embodiment, the thread-based message processing method includes the steps of:
step S10: the method comprises the steps that when the intelligent equipment detects a sending function, the target thread type of the sending function is obtained;
it can be understood that when the program based on the Android system is executed, there is usually an information transfer process between two functions, for example, a sending function as a sender transfers information to a receiving function as a receiver, but since the Android system has a main thread and a sub-thread in operation, when the execution mode of the sending function is determined, there is a difference between whether the receiving function performs subsequent information transfer in the main thread or the sub-thread. The main thread refers to a thread created as the process is started, and the sub-thread refers to a new thread created by the main thread.
In a specific implementation, for example, when a sending function a runs in the Android system, in order to determine a thread type in which a receiving function corresponding to the sending function is executed specifically, a target thread type of the sending function a may be obtained first. The target thread type is preset to be two types, namely a main thread type and a sub thread type, the main thread type indicates that the receiving function is to run in the main thread, and the sub thread type indicates that the receiving function is to run in the sub thread. Therefore, the target thread type of the send function is used to describe the thread type in which the corresponding receive function is located.
Step S20: searching a receiving function corresponding to the target thread type in the current receiving function set, and taking the searched receiving function as a target receiving function;
it should be understood that after the target thread type of the sending function a is obtained, the receiving function corresponding to the sending function a may be searched from the current receiving function set. Wherein, various receiving functions are pre-stored in the current receiving function set. When the receiving function is searched in the current receiving function set according to the target thread type, because the receiving functions in the receiving function set are different, the receiving function which can run in the main thread exists, and the receiving function which can run in the sub-thread also exists, the receiving function is marked through the thread type.
It can be understood that, after determining that the thread type of the sending function a is the target thread type, for example, the target thread type is the main thread type, the corresponding target receiving function B may also be found according to the main thread type, so that the found target receiving function B will run in the main thread. Therefore, both the sending function A and the target receiving function B will have the thread type set in advance.
Step S30: and performing message distribution in a target thread where the target receiving function is located through the target receiving function.
It should be understood that, for example, after the target thread type is a sub-thread type and the determined target receiving function is the receiving function C, the receiving function C is called and run in the sub-thread, so that the determination of the receiving function corresponding to the sending function a is also achieved. Moreover, by the scheme described in the embodiment, corresponding executable receiving functions can be determined for different sending functions; meanwhile, by flexibly and automatically determining the corresponding receiving function, an anonymous subclass Handler is not needed to be realized under the function, and compared with the method for developing the function according to the existing Android system, the method described in the embodiment enables codes not to be messy any more, and the readability is improved.
In addition, the technical scheme described in the present embodiment can be implemented by a singleton mode design mode, so that only one instance object exists, and unified management of functions can be implemented.
In this embodiment, by finding the receiving function corresponding to the target thread type, taking the found receiving function as a target receiving function, and performing message distribution in the target thread through the target receiving function, different executable receiving functions are determined based on different sending functions, and a technical problem that a better coupling property between the sending function and the receiving function cannot be ensured in an Android system is solved. Specifically, the selection of the receiving function is performed based on the thread type, so that the running thread type meets the running requirement.
Referring to fig. 3, fig. 3 is a flowchart illustrating a second embodiment of the thread-based message processing method according to the present invention, and the second embodiment of the thread-based message processing method according to the present invention is proposed based on the embodiment illustrated in fig. 2.
In the second embodiment, after the step S10, the method further includes:
step S101: acquiring the target function parameter type of the sending function;
it can be understood that, in order to ensure that information can be transferred between the sending function and the receiving function, the receiving function with the same function parameter type of the receiving function as that of the sending function may be preferentially used as the target receiving function determined in this embodiment to perform message distribution. Because, if the type of the function parameter of the sending function is different from that of the receiving function, the receiving function cannot acquire the data transferred by the sending function.
Step S102: and finding a corresponding current receiving function set according to the target function parameter type in a mapping relation, wherein the mapping relation comprises the corresponding relation between the function parameter type and the receiving function set, and the receiving function set comprises all receiving functions.
In a specific implementation, for example, if the sending function, that is, the target function parameter type of the sending function a, is integer, since there are a large number of selectable receiving functions, a receiving function with an integer function parameter type may be selected from among the receiving functions to perform message distribution. In order to find the receiving functions meeting the requirement of the parameter types more quickly according to the function parameter types, the receiving functions with the same function parameter types can be stored in the same set, so that the receiving function set is formed. Therefore, after the function parameter type of the sending function is determined to be integer, the receiving function set corresponding to the integer can be found according to the established mapping relation, and then the receiving function of the current executable operation is determined in the receiving function set, so that the method is quick, and the requirement that the parameter types of the sending function and the receiving function are the same is met.
In addition, in this embodiment, the type of the target function parameter of the sending function is determined first, and then the type of the target thread of the sending function is determined, so as to find the corresponding receiving function in two steps. For the search mode of the receiving function, a data structure can also be established, the function parameter type and the thread type are simultaneously stored in the data structure, and the corresponding receiving function can be directly searched through the data structure only through one step.
Of course, a Map type container can be established to implement the above technical solution. Specifically, if the Key of the Map type is a function parameter type, and a value corresponding to the Key is the data structure, the determination of the received function may be implemented based on the Map container, which is not limited in this example.
In this embodiment, by pre-establishing a mapping relationship including a correspondence between a function parameter type and a receiving function set, a receiving function that meets the requirement of the parameter type can be determined more quickly.
Referring to fig. 4, fig. 4 is a flowchart illustrating a third embodiment of the thread-based message processing method according to the present invention, and the third embodiment of the thread-based message processing method according to the present invention is proposed based on the embodiment illustrated in fig. 3.
In the third embodiment, before the step S10, the method further includes:
step S101': acquiring corresponding sample receiving functions according to a preset class object based on a Java reflection mechanism;
it is understood that, in order to more flexibly establish the mapping relationship including the corresponding relationship between the function parameter type and the received function set, the establishment of the mapping relationship can be realized based on a reflection mechanism of Java. The reflection mechanism based on Java refers to a capability that a program can access, detect and modify its own state or behavior under the use environment of Java, and specifically, the reflection mechanism only needs the name of a class to obtain the relevant information of the class.
In a specific implementation, a user may first specify a category name, and then dynamically load the category based on a reflection mechanism, so as to obtain the related information of the category. For example, the related information of the above categories may be encapsulated into an object, that is, the preset category object, and after the preset category object is obtained, the corresponding sample receiving functions are obtained according to the preset category object. As for the manner of obtaining the sample receiving function according to the preset class object, each sample receiving function corresponding to the preset class object can be obtained by a getMethods method of a Java reflection mechanism.
Step S102': determining a corresponding sample function parameter type according to the sample receiving function;
it should be understood that after obtaining each sample receiving function, in order to establish the mapping relationship, the sample function parameter type of each sample receiving function may be determined.
Step S103': and taking each sample receiving function with the same sample function parameter type as a sample receiving function set, establishing a corresponding relation between the sample function parameter type and the sample receiving function set, and adding the corresponding relation into the mapping relation.
In a specific implementation, for example, if the sample receiving functions obtained according to the preset class object are receiving functions a1, B1, and C1, respectively, and the function parameter types of the receiving functions a1, B1, and C1 are integer, and floating point, respectively, therefore, the receiving functions a1 and B1 are stored in the receiving function set corresponding to the integer type, and the receiving function C1 is stored in the receiving function set corresponding to the floating point type, which also establishes the corresponding relationship between the function parameter type and the receiving function set, and enriches the available corresponding relationship in the mapping relationship; and in a specific implementation process, the sending function can quickly determine the corresponding receiving function according to the type of the function parameter.
Further, in order to make the preset class objects richer and different, before the step S101', the method further includes:
step S1011: acquiring the reference information of the sending function;
it is understood that the preset class object can be established based on the reference information of the sending function, because the reference information can better describe the detailed information of the sending function.
Step S1012: and generating the preset class object according to the reference information.
In a specific implementation, the reference information may include a class name, a declared method, a declared field, and other information, and the preset class objects generated by different types of reference information are different. For example, the preset Class object generated by the reference information package may be a Class, a Method Class, a Field Class, or the like. Therefore, the preset class object can be acquired more flexibly by generating the preset class object according to the reference information; in addition, the preset class object acquired by the method can better describe the sending function, so that the finally established mapping relation can more accurately determine the receiving function.
Further, the reference information is class information, that is, class name information in the reference information is described, the preset class object is generated according to the reference information, and a reflection mechanism based on Java is used to obtain corresponding sample receiving functions according to the preset class object, which specifically includes: and generating a class object according to the class information, and acquiring corresponding sample receiving functions according to the class object based on a Java reflection mechanism.
In a specific implementation, if the obtained reference information is class information of a sending function, each sample receiving function corresponding to the class may be obtained according to the class information. The method for acquiring the receiving function does not need to create an instance, and only the class in the preset class object can be executed, so that if a development program is written or operated based on the method described in the embodiment, the method is concise and highly readable, and a proper receiving function can be well determined.
In the embodiment, each corresponding sample receiving function is obtained according to a preset class object through a Java-based reflection mechanism, so that the corresponding relation between the sample function parameter type and the sample receiving function set is established, and the mapping relation comprising the corresponding relation between the function parameter type and the receiving function set can be established more flexibly; meanwhile, the sending function can determine the corresponding receiving function more flexibly according to the type of the function parameter by applying the mapping relation.
Referring to fig. 5, fig. 5 is a flowchart illustrating a fourth embodiment of the method for processing a message based on a thread according to the present invention, and the fourth embodiment of the method for processing a message based on a thread according to the present invention is proposed based on the embodiment illustrated in fig. 2.
In the fourth embodiment, the step S30 specifically includes:
step S301: identifying the target thread type;
it will be appreciated that in order to determine the thread type at which the receive function is running, the target thread type may be identified first. The target thread type is preset to be two types, namely a main thread type and a sub thread type, the main thread type indicates that the receiving function is to run in the main thread, and the sub thread type indicates that the receiving function is to run in the sub thread. Therefore, the target thread type is used to describe the thread type in which the corresponding receive function is located.
Step S302: and when the target thread type is a main thread type, distributing the message in the main thread through the target receiving function, wherein the main thread type corresponds to the main thread.
It should be appreciated that when the identified thread type is a main thread type, the determined target receive function will run in the main thread; when the identified thread type is a sub-thread type, the determined target receiving function runs in the sub-thread, so that the receiving functions of different types stably run in a self-suitable running environment.
Further, when the target thread type is a main thread type, the message distribution is performed in the main thread through the target receiving function, which specifically includes: and when the target thread type is a main thread type, calling a Looper of the main thread through the target receiving function so as to enable the target receiving function to distribute the message in the main thread.
It can be understood that in the Message processing mechanism of the Android system, Message processing is implemented through four main components, which are a Message class, a Message operation class, a Message channel Looper, and a target. Wherein, one thread only has one Looper, which is used for circularly taking out the messages from the Message Queue in sequence. So the main thread will have one of its loopers.
In a specific implementation, when it is determined that the target thread type is the main thread type, the target receiving function distributes a message in the main thread, and specifically, because one thread has only one Looper, the target receiving function calls the Looper of the main thread itself to send and transfer the message.
In addition, when the target thread type is a sub-thread type, message distribution is performed in the sub-thread through the target receiving function, and the sub-thread type corresponds to the sub-thread.
Further, when the target thread type is a child thread type, the message distribution in the child thread is performed through the target receiving function, which specifically includes: and when the target thread type is the sub-thread type, creating a new thread and calling a Looper of the new thread so as to enable the target receiving function to distribute the message in the new thread.
In a specific implementation, when the target thread type is determined to be a sub-thread type, the target receiving function distributes a message in the sub-thread, that is, distributes a message in a new thread created by the main thread. Because one thread only has one Looper, the target receiving function can not call the Looper of the main thread but call the created Looper of the new thread to realize the message distribution in the new thread, thereby realizing the information interaction between the sending function and the receiving function under the premise of ensuring better coupling.
In the embodiment, the specific operation mode of the target receiving function is selected by identifying the type of the target thread, so that the thread operation environment adaptive to the target receiving function is determined; at the same time, the sending function is allowed to successfully determine a receiving function capable of performing a subsequent information distribution operation.
In addition, an embodiment of the present invention further provides a storage medium, where a thread-based message processing program is stored on the storage medium, and when executed by a processor, the thread-based message processing program implements the following operations:
when a sending function is detected, acquiring a target thread type of the sending function;
searching a receiving function corresponding to the target thread type in the current receiving function set, and taking the searched receiving function as a target receiving function;
and performing message distribution in a target thread where the target receiving function is located through the target receiving function.
Further, the thread-based message handler when executed by the processor further performs the following:
acquiring the target function parameter type of the sending function;
and finding a corresponding current receiving function set according to the target function parameter type in a mapping relation, wherein the mapping relation comprises the corresponding relation between the function parameter type and the receiving function set, and the receiving function set comprises all receiving functions.
Further, the thread-based message handler when executed by the processor further performs the following:
acquiring corresponding sample receiving functions according to a preset class object based on a Java reflection mechanism;
determining a corresponding sample function parameter type according to the sample receiving function;
and taking each sample receiving function with the same sample function parameter type as a sample receiving function set, establishing a corresponding relation between the sample function parameter type and the sample receiving function set, and adding the corresponding relation into the mapping relation.
Further, the thread-based message handler when executed by the processor further performs the following:
acquiring the reference information of the sending function;
and generating the preset class object according to the reference information.
Further, the thread-based message handler when executed by the processor further performs the following:
generating a class object according to the class information;
and acquiring corresponding sample receiving functions according to the class objects based on a Java reflection mechanism.
Further, the thread-based message handler when executed by the processor further performs the following:
identifying the target thread type;
when the target thread type is a main thread type, distributing messages in the main thread through the target receiving function, wherein the main thread type corresponds to the main thread;
or the like, or, alternatively,
and when the target thread type is a sub-thread type, distributing the message in the sub-thread through the target receiving function, wherein the sub-thread type corresponds to the sub-thread.
Further, the thread-based message handler when executed by the processor further performs the following:
and when the target thread type is a main thread type, calling a Looper of the main thread through the target receiving function so as to enable the target receiving function to distribute the message in the main thread.
Further, the thread-based message handler when executed by the processor further performs the following:
and when the target thread type is the sub-thread type, creating a new thread and calling a Looper of the new thread so as to enable the target receiving function to distribute the message in the new thread.
In this embodiment, by finding the receiving function corresponding to the target thread type, taking the found receiving function as a target receiving function, and performing message distribution in the current thread through the target receiving function, different executable receiving functions are determined based on different sending functions, and a technical problem that a better coupling property between the sending function and the receiving function cannot be ensured in an Android system is solved. Specifically, the selection of the receiving function is performed based on the thread type, so that the running thread type meets the running requirement.
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments. The use of the words first, second, third, etc. do not denote any order, but rather the words first, second, third, etc. are to be interpreted as names.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A thread-based message processing method, comprising:
the method comprises the steps that when the intelligent equipment detects a sending function, the target thread type of the sending function is obtained;
searching a receiving function corresponding to the target thread type in the current receiving function set, and taking the searched receiving function as a target receiving function;
carrying out message distribution in a target thread where the target receiving function is located through the target receiving function;
wherein, the sending function and the target receiving function both comprise preset thread types.
2. The thread-based message processing method of claim 1, wherein after the smart device obtains a target thread type of a send function when the send function is detected, the thread-based message processing method further comprises:
acquiring the target function parameter type of the sending function;
and finding a corresponding current receiving function set according to the target function parameter type in a mapping relation, wherein the mapping relation comprises the corresponding relation between the function parameter type and the receiving function set, and the receiving function set comprises all receiving functions.
3. The thread-based message processing method of claim 2, wherein before the smart device obtains the objective function parameter type of the send function when the send function is detected, the thread-based message processing method further comprises:
acquiring corresponding sample receiving functions according to a preset class object based on a Java reflection mechanism;
determining a corresponding sample function parameter type according to the sample receiving function;
and taking each sample receiving function with the same sample function parameter type as a sample receiving function set, establishing a corresponding relation between the sample function parameter type and the sample receiving function set, and adding the corresponding relation into the mapping relation.
4. The thread-based message processing method as claimed in claim 3, wherein before the Java-based reflection mechanism obtains the corresponding sample receiving functions according to the preset class objects, the thread-based message processing method further comprises:
acquiring the reference information of the sending function;
and generating the preset class object according to the reference information.
5. The thread-based message processing method of claim 4, wherein the reference information is class information;
correspondingly, the generating the preset class object according to the reference information and acquiring corresponding sample receiving functions according to the preset class object based on a reflection mechanism of Java specifically includes:
generating a class object according to the class information;
and acquiring corresponding sample receiving functions according to the class objects based on a Java reflection mechanism.
6. The thread-based message processing method according to any one of claims 1 to 5, wherein the performing, by the target receiving function, message distribution in the target thread in which the target receiving function is located specifically includes:
identifying the target thread type;
when the target thread type is a main thread type, distributing messages in the main thread through the target receiving function, wherein the main thread type corresponds to the main thread;
or the like, or, alternatively,
and when the target thread type is a sub-thread type, distributing the message in the sub-thread through the target receiving function, wherein the sub-thread type corresponds to the sub-thread.
7. The thread-based message processing method according to claim 6, wherein the distributing messages in the main thread through the target receiving function when the target thread type is the main thread type specifically comprises:
and when the target thread type is a main thread type, calling a Looper of the main thread through the target receiving function so as to enable the target receiving function to distribute the message in the main thread.
8. The thread-based message processing method according to claim 6, wherein when the target thread type is a child thread type, the message distribution is performed in the child thread through the target receiving function, specifically including:
and when the target thread type is the sub-thread type, creating a new thread and calling a Looper of the new thread so as to enable the target receiving function to distribute the message in the new thread.
9. A smart device, the smart device comprising: memory, a processor and a thread-based message handler stored on the memory and operable on the processor, the thread-based message handler when executed by the processor implementing the steps of the thread-based message processing method of any of claims 1 to 8.
10. A storage medium having stored thereon a thread-based message handler that, when executed by a processor, implements the steps of the thread-based message processing method of any of claims 1 to 8.
CN201711082986.1A 2017-11-06 2017-11-06 Thread-based message processing method, intelligent device and storage medium Active CN107818023B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711082986.1A CN107818023B (en) 2017-11-06 2017-11-06 Thread-based message processing method, intelligent device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711082986.1A CN107818023B (en) 2017-11-06 2017-11-06 Thread-based message processing method, intelligent device and storage medium

Publications (2)

Publication Number Publication Date
CN107818023A CN107818023A (en) 2018-03-20
CN107818023B true CN107818023B (en) 2021-06-15

Family

ID=61604865

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711082986.1A Active CN107818023B (en) 2017-11-06 2017-11-06 Thread-based message processing method, intelligent device and storage medium

Country Status (1)

Country Link
CN (1) CN107818023B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109005448B (en) * 2018-06-28 2021-06-15 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN109413502B (en) * 2018-09-29 2021-04-27 武汉斗鱼网络科技有限公司 Multithreading barrage message distribution method, device, equipment and storage medium
CN112363779A (en) * 2020-11-25 2021-02-12 王志平 Safety control method for dynamic link program
WO2022155937A1 (en) * 2021-01-23 2022-07-28 王志平 Security control method for dynamic link program
CN114546665B (en) * 2022-04-22 2022-08-05 恒生电子股份有限公司 Object processing method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8627335B2 (en) * 2006-11-13 2014-01-07 Oracle America, Inc. Method and apparatus for data space profiling of applications across a network
CN106407377A (en) * 2016-09-12 2017-02-15 北京百度网讯科技有限公司 Search method and device based on artificial intelligence
CN106598725A (en) * 2016-10-31 2017-04-26 武汉斗鱼网络科技有限公司 Android-based Handler memory leakage prevention device and method
CN106649036A (en) * 2016-11-24 2017-05-10 北京瑞星信息技术股份有限公司 Method and device for Linux network access monitoring
CN107015840A (en) * 2017-03-17 2017-08-04 南京南瑞继保电气有限公司 A kind of rapid implementation method of resolver and quick execution system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060044595A1 (en) * 2004-08-24 2006-03-02 Sharp Laboratories Of America Inc. Imaging job monitoring and pipelining
US9317392B2 (en) * 2012-10-10 2016-04-19 Webtrends, Inc. Methods and automated systems for testing, optimization, and analysis that preserve continuity in identities and status of users who access remote information from different contexts
RU2608883C2 (en) * 2014-12-26 2017-01-25 Общество С Ограниченной Ответственностью "Яндекс" Image processing method and electronic device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8627335B2 (en) * 2006-11-13 2014-01-07 Oracle America, Inc. Method and apparatus for data space profiling of applications across a network
CN106407377A (en) * 2016-09-12 2017-02-15 北京百度网讯科技有限公司 Search method and device based on artificial intelligence
CN106598725A (en) * 2016-10-31 2017-04-26 武汉斗鱼网络科技有限公司 Android-based Handler memory leakage prevention device and method
CN106649036A (en) * 2016-11-24 2017-05-10 北京瑞星信息技术股份有限公司 Method and device for Linux network access monitoring
CN107015840A (en) * 2017-03-17 2017-08-04 南京南瑞继保电气有限公司 A kind of rapid implementation method of resolver and quick execution system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Event Driven Web Video Summarization by Tag Localization and Key-Shot Identification;Meng Wang ET AL;《 IEEE Transactions on Multimedia》;20120123;第14卷(第4期);第975-985页 *
线程在Android开发中的应用;纪晓阳;《软件》;20130831;第34卷(第8期);第24-26,41页 *

Also Published As

Publication number Publication date
CN107818023A (en) 2018-03-20

Similar Documents

Publication Publication Date Title
CN107818023B (en) Thread-based message processing method, intelligent device and storage medium
US7877091B2 (en) Method and system for executing a container managed application on a processing device
CN110069308B (en) Page starting method and device, electronic equipment and storage medium
CN110753129A (en) Message transmission method, system, device, equipment and computer readable storage medium
CN110636124A (en) VPP cluster management method and device, electronic equipment and storage medium
CN113360807A (en) Page display method and device of mixed-mode mobile application and related equipment
CN113626225B (en) Program calling method, terminal device and medium
CN107172259B (en) Terminal and information interaction method and storage device based on two-dimensional code
CN107273226B (en) Method and device for integrating components in android system and calling integrated components
CN108052401B (en) System attribute monitoring method, terminal device and computer readable storage medium
CN111240998B (en) Test case processing method and device
CN111158777B (en) Component calling method, device and computer readable storage medium
CN110324722B (en) Method, device, equipment and storage medium for acquiring data in live broadcast room
CN110489326B (en) IDS-based HTTPAPI debugging method device, medium and equipment
CN109600738B (en) User information updating method, device, equipment and storage medium
CN111666074B (en) Web application customization method, related device and system
CN109840113B (en) Application data processing method and equipment, storage medium and terminal thereof
WO2022156427A1 (en) Dragging processing method and apparatus
CN113835790B (en) Paging page display method and device based on Android
CN110336693B (en) Method, device, equipment and storage medium for managing network block equipment
CN110069731B (en) Data processing method and device, electronic equipment and computer readable storage medium
CN115373869A (en) Process processing method and device based on AAR and electronic equipment
CN110955599A (en) Object creation method and device, electronic equipment and computer-readable storage medium
CN113032010B (en) Command transmission control method, terminal and computer readable storage medium
CN111767104B (en) Language type switching method and device, computer equipment and storage medium

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
TA01 Transfer of patent application right

Effective date of registration: 20200214

Address after: 201, room 518000, building A, No. 1, front Bay Road, Qianhai Shenzhen Guangdong Shenzhen Hong Kong cooperation zone (Qianhai business secretary)

Applicant after: Shenzhen leynew Network Media Co Ltd

Address before: 518000 Guangdong city of Shenzhen province Qianhai Shenzhen Hong Kong cooperation zone before Bay Road No. 1 building 201 room A (located in Shenzhen Qianhai business secretary Co. Ltd.)

Applicant before: Shenzhen leynew Mdt InfoTech Ltd

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant