CN110308942B - Method and related device for initializing controller - Google Patents

Method and related device for initializing controller Download PDF

Info

Publication number
CN110308942B
CN110308942B CN201910603757.2A CN201910603757A CN110308942B CN 110308942 B CN110308942 B CN 110308942B CN 201910603757 A CN201910603757 A CN 201910603757A CN 110308942 B CN110308942 B CN 110308942B
Authority
CN
China
Prior art keywords
initialization
thread
controller
protocol
function
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
CN201910603757.2A
Other languages
Chinese (zh)
Other versions
CN110308942A (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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201910603757.2A priority Critical patent/CN110308942B/en
Publication of CN110308942A publication Critical patent/CN110308942A/en
Application granted granted Critical
Publication of CN110308942B publication Critical patent/CN110308942B/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/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4403Processor initialisation

Abstract

The embodiment of the application discloses a method and a related device for initializing a controller, which are used for improving the initialization stability of the controller. The method in the embodiment of the application comprises the following steps: generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization; generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol; registering the initialization protocol in the initialization register; acquiring an initialization logic type of the controller according to the initialization protocol; and initializing the controller through the initialization register according to the initialization logic type, so that the stability of controller initialization is improved.

Description

Method and related device for initializing controller
Technical Field
The present application relates to the field of intelligent terminal technologies, and in particular, to a method for initializing a controller and a related device.
Background
With the continuous development of terminal technology, the popularization rate of intelligent terminals in social life is higher and higher, the frequency of using the intelligent terminals by users in daily life is higher and higher, and intelligent terminals applying various new technologies are also in use.
At present, applications based on different scenes of a terminal are in the tens of thousands, and as the number of applications installed on the terminal by a user is more and the running logic of the applications is more and more complex, usually, when the applications are run on the terminal, a plurality of controller programs are simultaneously started, and each controller needs to perform initialization operation before executing a corresponding task. Some tasks including the view UI content are also placed in the initialization logic, because the Android system explicitly specifies the requirement that the view UI cannot be updated in the child thread, which may lead to system crash if the child thread is still used for initialization in order to increase the initialization speed.
In the prior art, the initialization of the controller is accelerated through the child thread, but some tasks including the view UI content are also placed in the initialization logic, because the Android system explicitly specifies the requirement that the view UI cannot be updated in the child thread, the problem of system crash can be caused if the child thread is still used for initialization in order to accelerate the initialization speed.
Disclosure of Invention
The embodiment of the application provides a method and a related device for initializing a controller, which are used for improving the initialization stability of the controller.
A first aspect of an embodiment of the present application provides a method for initializing a controller, including:
generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization;
generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol;
registering the initialization protocol in the initialization register;
acquiring an initialization logic type of the controller according to the initialization protocol;
and initializing the controller through the initialization register according to the initialization logic type.
In a possible embodiment, the initialization protocol specifically includes:
the initialization protocol is a public type protocol named InitUpgrade, and comprises 4 protocol functions: onInitThread (), onInitMain (), getType (), getOrder (); the onInitThread protocol function is a public protocol function, the return value is a void type, and the protocol function is subsequently used for executing the initialization service logic related to the sub-thread;
the access right and the return value type of the onInitMain protocol function are consistent with the onInitThread protocol function, and the onInitMain protocol function is subsequently used for executing the initialization service logic of the main thread;
the getType () protocol function of the function is public access right, the return value is int type, and the int type return value comprises three constants: INIT _ read is 1, INIT _ MAIN is 2, INIT _ MAIN + INIT _ read is 3; the return value of the getType function can only be the value of INIT _ THREAD or INIT _ MAIN + INIT _ THREAD, namely the return value of 1 indicates that the controller initialization logic type only has a sub-THREAD initialization logic type, the return value of 2 indicates that the controller initialization logic type only has a MAIN THREAD initialization logic type, and the return value of 3 indicates that the controller initialization logic type has both a sub-THREAD initialization logic type and a MAIN THREAD initialization logic type;
the getOrider () is a protocol function for controlling the execution sequence of the thread, and is used for controlling the sequence of executing the protocol function onInitMain () and the protocol function onInitThread (); if the getOrider () protocol function return value is 0, it means that the onInitThread () protocol function is executed first and then the onInitMain () protocol function is executed, and if the getOrider () protocol function return value is 1, it means that the onInitMain () protocol function is executed first and then the onInitThread () protocol function is executed.
In a possible embodiment, the generating an initialization register specifically includes:
generating an initialization register by an initialization register function; the addlnitregister function addInitRegister access right is a public right, the return value is a void type return value, and the initialization register comprises two access parameters: a parameter myInitHandler of the type of IInit protocol and a priority parameter M representing the controller;
defining a global collection object List for storing information of the initialization register data; initializing the List of collection objects in the initializer register function.
In a possible embodiment, the generating an initialization register further includes:
in the addlnitregster function, emptying the myInitHandler; if the myInitHandler is empty, returning the function addInitRegister through a return, otherwise, judging whether the myInitHandler is contained, if the myInitHandler is contained, terminating logic through a return statement, otherwise, adding the myInitHandler to the collection object List;
registering the initialization protocol in the initialization register specifically includes:
inheriting the initialization protocol by means of instantiations and overwriting the onInitThread (), onInitMain (), getType (), getOrder () protocol functions.
In a possible embodiment, the acquiring an initialization logic type of the controller according to the initialization protocol specifically includes:
firstly, judging whether the listInit of the set object List is empty or not, and if the listInit of the set object List is empty, directly returning through a return statement so as to terminate an initialization process; if not, obtaining the number count of the controllers in the listInit set of the set object List through a listInit () function, if the count is 0, indicating that no controller needing initialization exists in the listInit set, and terminating the initialization process through return.
If the count is not 0, sequentially taking out the controller object items which need to be initialized in the listInit set in a traversal mode, wherein the controller object items conform to the InitUpdrade protocol definition; by calling the getType () function in the controller object item, the size of the return value is judged, and the return value is one of the following three return values: the controller initialization logic type includes that INIT _ THREAD is 1, the controller initialization logic type only includes a sub-THREAD initialization logic type, INIT _ MAIN is 2, the controller initialization logic type only includes a MAIN THREAD initialization logic type, INIT _ MAIN + INIT _ THREAD is 3, and the controller initialization logic type includes both the sub-THREAD initialization logic type and the MAIN THREAD initialization logic type.
In a possible embodiment, the initializing the controller by the initialization register according to the initialization logic type further includes:
if the returned value of the getType () function is INIT _ THREAD equal to 1, constructing a first sub-THREAD, then calling a thread.start () function in the first sub-THREAD to start, and realizing the initialization operation of the controller object item in the first sub-THREAD by calling an item.ONINITThread () function;
if the returned value of the getType () function is INIT _ MAIN ═ 2, constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread, and then calling an item.onlntmain () function in a code block of the Runnable to realize the initialization operation of the controller object item in the main thread.
In a possible embodiment, the initializing the controller by the initialization register according to the initialization logic type further includes:
if the returned value of the getType () function is INIT _ MAIN + INIT _ THREAD which is 3, constructing a first sub-THREAD, and then calling a thread.start () function in the first sub-THREAD to start; constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread;
implementing an initialization operation of the controller object item corresponding to a sub-thread initialization type in the first sub-thread by calling an item.
And realizing the initialization operation of the controller object item corresponding to the initialization type of the main thread in the main thread by calling an item.
A second aspect of an embodiment of the present application provides a controller initialization apparatus, including:
the initialization register generating unit is used for generating an initialization register which is used for managing and analyzing the controller needing initialization; an initialization protocol generation unit, configured to generate an initialization protocol, where the initialization protocol is used to implement a unification process of an initialization logic function of the controller; a registration unit configured to register the initialization protocol in the initialization register; an initialization logic type obtaining unit, configured to obtain an initialization logic type of the controller according to the initialization protocol; and the execution unit is used for initializing the controller through the initialization register according to the initialization logic type.
A third aspect of the present application provides a computer-readable storage medium having stored therein instructions, which, when executed on a computer, cause the computer to perform the method of the above-described aspects.
A fourth aspect of the present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of the above-described aspects.
According to the technical scheme, the embodiment of the application has the following advantages: generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization; generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol; registering the initialization protocol in the initialization register; acquiring an initialization logic type of the controller according to the initialization protocol; and initializing the controller through the initialization register according to the initialization logic type. In the embodiment of the application, the controller corresponding to the initialization type of the sub-thread is put into the sub-thread for initialization operation by judging the initialization logic type of the controller needing initialization, and the controller corresponding to the initialization type of the main thread is put into the main thread for initialization operation, so that the initialization stability of the controller is improved.
Drawings
Fig. 1 is a flowchart of a method for initializing a controller according to an embodiment of the present disclosure;
fig. 2 is a schematic structural diagram of a possible controller initialization apparatus according to an embodiment of the present disclosure;
fig. 3 is a schematic hardware structure diagram of a possible computer-readable storage medium according to an embodiment of the present disclosure.
Detailed Description
The embodiment of the application provides a method and a related device for initializing a controller, which are used for improving the initialization speed of the controller.
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, a flowchart of a method for switching video sharpness is provided, which includes:
101. generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization;
generating an initialization register by initializing a register function Public void addInitRegister (IInit myInitHandler, int M) { }; the access right in the initialization register function addlnitregister is public right, the return value is a void type return value, the name of the function is addlnitregister, and the initialization register comprises two parameter entries: a parameter myInitHandler of the type of IInit protocol and a priority parameter M representing the controller; by generating a register, the controller can be managed in a centralized way, and the initialization speed of the controller is improved.
Optionally, a global set object List may be defined, which is used to store the information of the initialization register data; initializing the set object List in the initializer register function, wherein the specific method for initializing the set object List is as follows: list < IInit > listInits ═ new ArrayList < IInit > (). By collecting the object List, all the registered protocol objects can be maintained, and the initialization speed of the controller is improved.
Optionally, in the addlnitregster function, the myInitHandler is determined to be null by calling if (myInitHandler), and if the expression is true, the myInitHandler is null, otherwise, the expression is not null; if myInitHandler is empty, the function addinitpointer is returned by return, otherwise it is determined whether myInitHandler is included by calling listinits. Therefore, the problem of null pointer abnormity of subsequent service logic can be avoided, the system stability is improved, and the controller initialization speed is increased.
102. Generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol;
in order to implement the unified processing of the initialization logic, an initialization protocol is first generated, and the unified processing of the initialization logic function is implemented through the protocol.
The said page is formed by the function Public interface initUpdide
Public void onInitThread();
Public void onInitMain();
Public int getType();
Public int getOrder();};
The initialization protocol is a public type protocol named InitUpgrade, and comprises 4 protocol functions: onInitThread (), onInitMain (), getType (), getOrder (); the onInitThread protocol function is a public protocol function, the return value is a void type, and the protocol function is subsequently used for executing the initialization service logic related to the sub-thread;
the access right and the return value type of the onInitMain protocol function are consistent with the onInitThread protocol function, and the onInitMain protocol function is subsequently used for executing the initialization service logic of the main thread;
the getType () protocol function of the function is public access right, the return value is int type, and the int type return value comprises three constants: INIT _ read is 1, INIT _ MAIN is 2, INIT _ MAIN + INIT _ read is 3; the return value of the getType function can only be the value of INIT _ THREAD or INIT _ MAIN + INIT _ THREAD, namely the return value of 1 indicates that the controller initialization logic type only has a sub-THREAD initialization logic type, the return value of 2 indicates that the controller initialization logic type only has a MAIN THREAD initialization logic type, and the return value of 3 indicates that the controller initialization logic type has both a sub-THREAD initialization logic type and a MAIN THREAD initialization logic type;
the getOrider () is a protocol function for controlling the execution sequence of the thread, and is used for controlling the sequence of executing the protocol function onInitMain () and the protocol function onInitThread (); if the getOrider () protocol function return value is 0, it means that the onInitThread () protocol function is executed first and then the onInitMain () protocol function is executed, and if the getOrider () protocol function return value is 1, it means that the onInitMain () protocol function is executed first and then the onInitThread () protocol function is executed. The initialization protocol is used for realizing the unification processing of the initialization logic function, different types of initialization service types can be judged and distinguished, the adaptability of the protocol can be better expanded, and the sequentiality of logic execution can be dynamically controlled; and the design of getOrider () and the design of getType () function can dynamically make more combinations of protocol logic sequences, so that the method can adapt to more application scenes, use and the like.
103. Registering the initialization protocol in the initialization register;
inheriting the initialization protocol by means of instantiations and overwriting the onInitThread (), onInitMain (), getType (), getOrder () protocol functions.
104. Acquiring an initialization logic type of the controller according to the initialization protocol;
firstly, judging whether the listInit of the set object List is empty or not, and if the listInit of the set object List is empty, directly returning through a return statement so as to terminate an initialization process; if not, obtaining the number count of the controllers in the listInit set of the set object List through a listInit () function, if the count is equal to 0, indicating that no controller needing initialization is in the listInit set, and terminating the initialization process through return, thereby avoiding program logic errors.
If the count is not 0, sequentially taking out the controller object items which need to be initialized in the listInit set in a traversal mode, wherein the controller object items conform to the InitUpdrade protocol definition; by calling the getType () function in the controller object item, the size of the return value is judged, and the return value is one of the following three return values: the controller initialization logic type includes that INIT _ THREAD is 1, the controller initialization logic type only includes a sub-THREAD initialization logic type, INIT _ MAIN is 2, the controller initialization logic type only includes a MAIN THREAD initialization logic type, INIT _ MAIN + INIT _ THREAD is 3, and the controller initialization logic type includes both the sub-THREAD initialization logic type and the MAIN THREAD initialization logic type.
105. And initializing the controller through the initialization register according to the initialization logic type.
If the getType () function return value is INIT _ THREAD ═ 1, a first sub-THREAD is constructed by a THREAD ═ newThread () method, then a THREAD.
If the returned value of the getType () function is INIT _ MAIN ═ 2, constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread, and then calling an item.onlntmain () function in a code block of the Runnable to realize the initialization operation of the controller object item in the main thread.
If the returned value of the getType () function is INIT _ MAIN + INIT _ THREAD is 3, constructing a first sub-THREAD by a THREAD () method, and then calling a THREAD. Constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread; judging the execution sequence of a main thread and a sub-thread through a return value of a getOrider () function, if the return value of the getOrider () protocol function is 0, executing a main thread task first, namely executing the onInitThread () protocol function first and then executing the onInitMain () protocol function, and if the return value of the getOrider () protocol function is 1, executing a sub-thread task first, namely executing the onInitMain () protocol function first and then executing the onInitThread () protocol function;
optionally, the determination of the execution order of the MAIN THREAD and the sub THREAD is performed through the return value of getOrider () only when the return value of the getType () function is INIT _ MAIN + INIT _ THREAD is 3, otherwise, the return value of getOrider () is not processed, that is, the function return information of getOrider () is ignored, so that the initialization speed can be increased.
Then, the initialization operation of the controller object item corresponding to the initialization type of the sub thread in the first sub thread is realized by calling an item. And realizing the initialization operation of the controller object item corresponding to the initialization type of the main thread in the main thread by calling an item.
By acquiring the initialization logic type of the controller and then initializing the controller through the initialization register according to the initialization logic type, the controller with the sub-thread initialization logic type can be placed into the sub-thread for initialization, and the controller with the main thread initialization logic type is placed into the main thread for initialization, so that system crash caused by the fact that the controller with the main thread initialization logic type is placed into the sub-thread for initialization mistakenly can be avoided, and the stability of controller initialization is improved.
Optionally, for the initialization process of the controller with the initialization logic type of the sub-thread initialization type, the priority M of the controller may be obtained according to a preset priority policy;
the preset priority policy can be automatically acquired from a local or server, or the priority policy manually selected by a user can be acquired, and the priority policy is used for determining the priority sequence when the controller is initialized.
Acquiring an urgency factor K of the controller, wherein the K is an integer between [10,100 ]; k represents the urgency degree of a task corresponding to the controller, and the larger the value of K is, the more urgent the task is, the task is to be executed preferentially;
obtaining a complexity factor B of the controller, wherein B is N Q, N is a natural number representing algorithm complexity, if N is 0, N is also assigned to be 1 to avoid occurrence of business logic abnormity, Q is an increasing factor influencing the complexity factor B and is used for increasing the influence degree of the complexity factor B, and Q is a positive number which is more than or equal to 1; and the complexity of the algorithm is used for evaluating the complexity of the algorithm used for processing the task, and the larger the number of the task complexity B is, the more complex the task corresponding to the controller is.
The priority M of the controller is calculated by the following formula:
m ═ T × K/B; t is an adjusting coefficient, is an integer between 1 and 100, and can be taken as the value according to specific situations. The M and the K, B form a square relation, so that the influence degree of the urgency factor K and the complexity factor B can be enlarged, the value range interval distribution of the M is more dispersed, and the priority M of different controllers can be distinguished conveniently at the later stage. Therefore, M is in proportion to K and in inverse proportion to B, namely, the higher the task urgency degree is, the task is processed with higher priority, the task complexity is higher, the task is processed with higher time, and the priority is set to be lower, so that the controllers corresponding to the tasks with high urgency degree and low complexity can be initialized with higher priority, and the controller initialization speed can be increased.
And initializing the controller through the initialization register according to the priority M of the controller.
Acquiring a first thread quantity factor Num1 according to the current system performance, wherein the system performance comprises system processor performance or system memory performance; for example, the first thread quantity factor Num1 is obtained by obtaining the size of the system memory, for example, if the system memory is less than or equal to 2G, it is determined as the low-end device, otherwise, it is determined as the high-end device. Constructing a mapping relation between system performance and thread quantity, wherein the specific mapping function design is as follows:
Num1=C*mem
where C is a tuning parameter and mem is the system memory capacity, the first thread count factor Num1 represents the total first thread count to be opened, the first thread count factor. Optionally, Num1 ranges from [1,10], taking the maximum value if it is outside the range interval.
Obtaining a second thread quantity factor Num2 according to the quantity of the controllers with the priority M greater than a preset value in the set object List;
and comparing the sizes of the first thread quantity factor Num1 and the second thread quantity factor Num2, and taking the larger value as the number Num of the main threads to be created.
Generating a corresponding number of main threads according to the number Num of the main threads;
and generating a sub-thread corresponding to the main thread according to the task information of the controller, and initializing the controller through the sub-thread.
The initialization List referenced in the collection object List is executed by opening up multiple threads. The method includes the steps that firstly, the number initNum of controllers needing initialization is obtained by calling a listinits size () method, then an integer X is obtained by calling the number initNum to divide Num, then X tasks are executed according to each thread, and optionally, if the number initNum is divided by Num to have a remainder, controllers corresponding to the remainder are all placed in the last thread to be initialized.
In each main thread, acquiring task information of a corresponding controller by a listinits.get (i) method, calling a start function in a thread pool to open up a sub-thread, and putting the acquired task in the opened sub-thread for processing. Therefore, tasks processed in the main thread can be completely switched to the sub-threads to be processed originally, functions of the non-main thread can be switched to instantiated sub-threads to be processed originally, and due to the fact that a plurality of sub-thread tasks are opened up, the purpose that a plurality of initialization processes are parallel can be achieved, and the initialization speed and stability of the controller are improved.
The embodiments of the present application are described above from the perspective of a method of initializing a controller, and are described below from the perspective of a controller initialization apparatus.
Referring to fig. 2, fig. 2 is a schematic diagram of an embodiment of a possible controller initialization apparatus 20 according to an embodiment of the present application, where the controller initialization apparatus 20 specifically includes:
an initialization register generation unit 201, configured to generate an initialization register, where the initialization register is used to perform management and analysis operations on a controller that needs to be initialized;
specifically, the initialization register generating unit 201 generates an initialization register by an initialization register function Public void addinitregster (IInit myInitHandler, int M) { }; the access right in the initialization register function addlnitregister is public right, the return value is a void type return value, the name of the function is addlnitregister, and the initialization register comprises two parameter entries: a parameter myInitHandler of the type of IInit protocol and a priority parameter M representing the controller; by generating a register, the controller can be managed in a centralized way, and the initialization speed of the controller is improved.
Optionally, in a possible embodiment, the initialization register generating unit 201 may be further specifically configured to: a global set object List may be defined for storing information of the initialization register data; initializing the set object List in the initializer register function, wherein the specific method for initializing the set object List is as follows: list < IInit > listInits ═ new ArrayList < IInit > (). By collecting the object List, all the registered protocol objects can be maintained, and the initialization speed of the controller is improved.
Optionally, in a possible embodiment, the initialization register generating unit 201 may be further specifically configured to: in the addlnitregster function, emptying the myInitHandler by calling if (null), if the expression is true, the myInitHandler is empty, otherwise, the expression is not empty; if myInitHandler is empty, the function addinitpointer is returned by return, otherwise it is determined whether myInitHandler is included by calling listinits. Therefore, the problem of null pointer abnormity of subsequent service logic can be avoided, the system stability is improved, and the controller initialization speed is increased.
An initialization protocol generation unit 202, configured to generate an initialization protocol, where a unification process of an initialization logic function of the controller is implemented by the initialization protocol;
specifically, in order to implement unified processing of initialization logic, first, the initialization protocol generation unit 202 needs to generate an initialization protocol, and the protocol is used to implement unified processing of initialization logic functions, where the initialization protocol specifically includes:
function Public interface initUpdide
Public void onInitThread();
Public void onInitMain();
Public int getType();
Public int getOrder();};
The initialization protocol is a public type protocol named InitUpgrade, and comprises 4 protocol functions: onInitThread (), onInitMain (), getType (), getOrder (); the onInitThread protocol function is a public protocol function, the return value is a void type, and the protocol function is subsequently used for executing the initialization service logic related to the sub-thread;
the access right and the return value type of the onInitMain protocol function are consistent with the onInitThread protocol function, and the onInitMain protocol function is subsequently used for executing the initialization service logic of the main thread;
the getType () protocol function of the function is public access right, the return value is int type, and the int type return value comprises three constants: INIT _ read is 1, INIT _ MAIN is 2, INIT _ MAIN + INIT _ read is 3; the return value of the getType function can only be the value of INIT _ THREAD or INIT _ MAIN + INIT _ THREAD, namely the return value of 1 indicates that the controller initialization logic type only has a sub-THREAD initialization logic type, the return value of 2 indicates that the controller initialization logic type only has a MAIN THREAD initialization logic type, and the return value of 3 indicates that the controller initialization logic type has both a sub-THREAD initialization logic type and a MAIN THREAD initialization logic type;
the getOrider () is a protocol function for controlling the execution sequence of the thread, and is used for controlling the sequence of executing the protocol function onInitMain () and the protocol function onInitThread (); if the getOrider () protocol function return value is 0, it means that the onInitThread () protocol function is executed first and then the onInitMain () protocol function is executed, and if the getOrider () protocol function return value is 1, it means that the onInitMain () protocol function is executed first and then the onInitThread () protocol function is executed. The initialization protocol is used for realizing the unification processing of the initialization logic function, different types of initialization service types can be judged and distinguished, the adaptability of the protocol can be better expanded, and the sequentiality of logic execution can be dynamically controlled; and the design of getOrider () and the design of getType () function can dynamically make more combinations of protocol logic sequences, so that the method can adapt to more application scenes, use and the like.
A registering unit 203, configured to register the initialization protocol in the initialization register, specifically, the registering unit 203 inherits the initialization protocol and overwrites the onlnitthread (), onlnitmain (), getType (), getOrder () protocol functions by way of instantiations.
An initialization logic type obtaining unit 204, configured to obtain an initialization logic type of the controller according to the initialization protocol; specifically, the initialization logic type obtaining unit 204 is specifically configured to: firstly, judging whether the listInit of the set object List is empty or not, and if the listInit of the set object List is empty, directly returning through a return statement so as to terminate an initialization process; if not, obtaining the number count of the controllers in the listInit set of the set object List through a listInit () function, if the count is equal to 0, indicating that no controller needing initialization is in the listInit set, and terminating the initialization process through return, thereby avoiding program logic errors.
If the count is not 0, the initialization logic type obtaining unit 204 sequentially takes out the controller object items that need to be initialized in the listInit set in a traversal manner, where the controller object items conform to the initupplide protocol definition; by calling the getType () function in the controller object item, the size of the return value is judged, and the return value is one of the following three return values: the controller initialization logic type includes that INIT _ THREAD is 1, the controller initialization logic type only includes a sub-THREAD initialization logic type, INIT _ MAIN is 2, the controller initialization logic type only includes a MAIN THREAD initialization logic type, INIT _ MAIN + INIT _ THREAD is 3, and the controller initialization logic type includes both the sub-THREAD initialization logic type and the MAIN THREAD initialization logic type.
An execution unit 205, configured to initialize the controller through the initialization register according to the initialization logic type; specifically, if the return value is INIT _ THREAD is 1, the execution unit 205 constructs a first sub-THREAD through a THREAD _ new () method, then calls a THREAD _ start () function in the first sub-THREAD to start, and calls an item _ onlnitthread () function to implement an initialization operation of the controller object item in the first sub-THREAD.
If the return value is INIT _ MAIN ═ 2, the execution unit 205 constructs a thread switch object Handler through the Handler class provided in the Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread, and then calling an item.onlntmain () function in a code block of the Runnable to realize the initialization operation of the controller object item in the main thread.
If the return value is INIT _ MAIN + INIT _ THREAD is 3, the execution unit 205 constructs a first sub-THREAD by a THREAD () method, and then invokes a THREAD. Constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread; judging the execution sequence of a main thread and a sub-thread through a return value of a getOrider () function, if the return value of the getOrider () protocol function is 0, executing a main thread task first, namely executing the onInitThread () protocol function first and then executing the onInitMain () protocol function, and if the return value of the getOrider () protocol function is 1, executing a sub-thread task first, namely executing the onInitMain () protocol function first and then executing the onInitThread () protocol function;
optionally, in a possible embodiment, the execution unit 205 may further specifically be configured to: the MAIN THREAD and the sub THREAD execution order are judged through the return value of getOrider () only when the function return value of getType () is INIT _ MAIN + INIT _ THREAD is 3, otherwise the return value of getOrider () is not processed, namely the function return information of getOrider () is ignored, so that the initialization speed can be improved.
Then, the initialization operation of the controller object item corresponding to the initialization type of the sub thread in the first sub thread is realized by calling an item. And realizing the initialization operation of the controller object item corresponding to the initialization type of the main thread in the main thread by calling an item.
By acquiring the initialization logic type of the controller and then initializing the controller through the initialization register according to the initialization logic type, the controller with the sub-thread initialization logic type can be placed into the sub-thread for initialization, and the controller with the main thread initialization logic type is placed into the main thread for initialization, so that system crash caused by the fact that the controller with the main thread initialization logic type is placed into the sub-thread for initialization mistakenly can be avoided, and the stability of controller initialization is improved.
Optionally, in a possible embodiment, the controller initialization apparatus 20 further includes a priority obtaining unit, and for an initialization process of a controller whose initialization logic type is a child thread initialization type, the priority obtaining unit may first obtain the priority M of the controller according to a preset priority policy;
the priority acquiring unit may automatically acquire a preset priority policy from a local or server, or may acquire a priority policy manually selected by a user, where the priority policy is used to determine a priority order when the controller is initialized.
Acquiring an urgency factor K of the controller, wherein the K is an integer between [10,100 ]; k represents the urgency degree of a task corresponding to the controller, and the larger the value of K is, the more urgent the task is, the task is to be executed preferentially;
obtaining a complexity factor B of the controller, wherein B is N Q, N is a natural number representing algorithm complexity, if N is 0, N is also assigned to be 1 to avoid occurrence of business logic abnormity, Q is an increasing factor influencing the complexity factor B and is used for increasing the influence degree of the complexity factor B, and Q is a positive number which is more than or equal to 1; and the complexity of the algorithm is used for evaluating the complexity of the algorithm used for processing the task, and the larger the number of the task complexity B is, the more complex the task corresponding to the controller is.
The priority M of the controller is calculated by the following formula:
m ═ T × K/B; t is an adjusting coefficient, is an integer between 1 and 100, and can be taken as the value according to specific situations. The M and the K, B form a square relation, so that the influence degree of the urgency factor K and the complexity factor B can be enlarged, the value range interval distribution of the M is more dispersed, and the priority M of different controllers can be distinguished conveniently at the later stage. Therefore, M is in proportion to K and in inverse proportion to B, namely, the higher the task urgency degree is, the task is processed with higher priority, the task complexity is higher, the task is processed with higher time, and the priority is set to be lower, so that the controllers corresponding to the tasks with high urgency degree and low complexity can be initialized with higher priority, and the controller initialization speed can be increased.
Optionally, in a possible embodiment, the execution unit 205 is further configured to: and initializing the controller through the initialization register according to the priority M of the controller acquired by the priority acquisition unit.
Acquiring a first thread quantity factor Num1 according to the current system performance, wherein the system performance comprises system processor performance or system memory performance; for example, the first thread quantity factor Num1 is obtained by obtaining the size of the system memory, for example, if the system memory is less than or equal to 2G, it is determined as the low-end device, otherwise, it is determined as the high-end device. Constructing a mapping relation between system performance and thread quantity, wherein the specific mapping function design is as follows:
Num1=C*mem
where C is a tuning parameter and mem is the system memory capacity, the first thread count factor Num1 represents the total first thread count to be opened, the first thread count factor. Optionally, Num1 ranges from [1,10], taking the maximum value if it is outside the range interval.
Obtaining a second thread quantity factor Num2 according to the quantity of the controllers with the priority M greater than a preset value in the set object List;
and comparing the sizes of the first thread quantity factor Num1 and the second thread quantity factor Num2, and taking the larger value as the number Num of the main threads to be created.
Generating a corresponding number of main threads according to the number Num of the main threads;
and generating a sub-thread corresponding to the main thread according to the task information of the controller, and initializing the controller through the sub-thread.
The initialization List referenced in the collection object List is executed by opening up multiple threads. The method includes the steps that firstly, the number initNum of controllers needing initialization is obtained by calling a listinits size () method, then an integer X is obtained by calling the number initNum to divide Num, then X tasks are executed according to each thread, and optionally, if the number initNum is divided by Num to have a remainder, controllers corresponding to the remainder are all placed in the last thread to be initialized.
In each main thread, acquiring task information of a corresponding controller by a listinits.get (i) method, calling a start function in a thread pool to open up a sub-thread, and putting the acquired task in the opened sub-thread for processing. Therefore, tasks processed in the main thread can be completely switched to the sub-threads to be processed originally, functions of the non-main thread can be switched to instantiated sub-threads to be processed originally, and due to the fact that a plurality of sub-thread tasks are opened up, the purpose that a plurality of initialization processes are parallel can be achieved, and the initialization speed and stability of the controller are improved.
Referring to fig. 3, fig. 3 is a schematic diagram of an embodiment of a computer-readable storage medium according to the present application.
As shown in fig. 3, the present embodiment provides a computer-readable storage medium 400, on which a computer program 411 is stored, the computer program 411 implementing the following steps when executed by a processor:
generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization;
generating an initialization register by initializing a register function Public void addInitRegister (IInit myInitHandler, int M) { }; the access right in the function of the initialization register is public right, the return value is a void type return value, the name of the function is addInitRegister, and the initialization register comprises two parameter entries: a parameter myInitHandler of the type of IInit protocol and a priority parameter M representing the controller; by generating a register, the controller can be managed in a centralized way, and the initialization speed of the controller is improved.
Optionally, in a possible embodiment, the computer program 411 when executed by a processor implements the following steps: a global set object List may be defined for storing information of the initialization register data; initializing the set object List in the initializer register function, wherein the specific method for initializing the set object List is as follows: list < IInit > listInits ═ new ArrayList < IInit > (). By collecting the object List, all the registered protocol objects can be maintained, and the initialization speed of the controller is improved.
Optionally, in a possible embodiment, the computer program 411 when executed by a processor implements the following steps: in the addlnitregster function, emptying the myInitHandler by calling if (null), if the expression is true, the myInitHandler is empty, otherwise, the expression is not empty; if myInitHandler is empty, the function addinitpointer is returned by return, otherwise it is determined whether myInitHandler is included by calling listinits. Therefore, the problem of null pointer abnormity of subsequent service logic can be avoided, the system stability is improved, and the controller initialization speed is increased.
Generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol;
in order to implement the unified processing of the initialization logic, an initialization protocol is first generated, and the unified processing of the initialization logic function is implemented through the protocol.
The initialization protocol is a public type protocol named InitUpgrade, and comprises 4 protocol functions: onInitThread (), onInitMain (), getType (), getOrder (); the onInitThread protocol function is a public protocol function, the return value is a void type, and the protocol function is subsequently used for executing the initialization service logic related to the sub-thread;
the access right and the return value type of the onInitMain protocol function are consistent with the onInitThread protocol function, and the onInitMain protocol function is subsequently used for executing the initialization service logic of the main thread;
the getType () protocol function of the function is public access right, the return value is int type, and the int type return value comprises three constants: INIT _ read is 1, INIT _ MAIN is 2, INIT _ MAIN + INIT _ read is 3; the return value of the getType function can only be the value of INIT _ THREAD or INIT _ MAIN + INIT _ THREAD, namely the return value of 1 indicates that the controller initialization logic type only has a sub-THREAD initialization logic type, the return value of 2 indicates that the controller initialization logic type only has a MAIN THREAD initialization logic type, and the return value of 3 indicates that the controller initialization logic type has both a sub-THREAD initialization logic type and a MAIN THREAD initialization logic type;
the getOrider () is a protocol function for controlling the execution sequence of the thread, and is used for controlling the sequence of executing the protocol function onInitMain () and the protocol function onInitThread (); if the getOrider () protocol function return value is 0, it means that the onInitThread () protocol function is executed first and then the onInitMain () protocol function is executed, and if the getOrider () protocol function return value is 1, it means that the onInitMain () protocol function is executed first and then the onInitThread () protocol function is executed. The initialization protocol is used for realizing the unification processing of the initialization logic function, different types of initialization service types can be judged and distinguished, the adaptability of the protocol can be better expanded, and the sequentiality of logic execution can be dynamically controlled; and the design of getOrider () and the design of getType () function can dynamically make more combinations of protocol logic sequences, so that the method can adapt to more application scenes, use and the like.
Registering the initialization protocol in the initialization register;
inheriting the initialization protocol by means of instantiations and overwriting the onInitThread (), onInitMain (), getType (), getOrder () protocol functions.
Acquiring an initialization logic type of the controller according to the initialization protocol;
firstly, judging whether the listInit of the set object List is empty or not, and if the listInit of the set object List is empty, directly returning through a return statement so as to terminate an initialization process; if not, obtaining the number count of the controllers in the listInit set of the set object List through a listInit () function, if the count is equal to 0, indicating that no controller needing initialization is in the listInit set, and terminating the initialization process through return, thereby avoiding program logic errors.
If the count is not 0, sequentially taking out the controller object items which need to be initialized in the listInit set in a traversal mode, wherein the controller object items conform to the InitUpdrade protocol definition; by calling the getType () function in the controller object item, the size of the return value is judged, and the return value is one of the following three return values: the controller initialization logic type includes that INIT _ THREAD is 1, the controller initialization logic type only includes a sub-THREAD initialization logic type, INIT _ MAIN is 2, the controller initialization logic type only includes a MAIN THREAD initialization logic type, INIT _ MAIN + INIT _ THREAD is 3, and the controller initialization logic type includes both the sub-THREAD initialization logic type and the MAIN THREAD initialization logic type.
And initializing the controller through the initialization register according to the initialization logic type.
If the return value is INIT _ THREAD ═ 1, a first sub-THREAD is constructed by a THREAD _ THREAD () method, then a THREAD _ start () function in the first sub-THREAD is called to start, and an initialization operation of the controller object item in the first sub-THREAD is realized by calling an item _ onlnitthread () function.
If the return value is INIT _ MAIN which is 2, constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread, and then calling an item.onlntmain () function in a code block of the Runnable to realize the initialization operation of the controller object item in the main thread.
If the return value is INIT _ MAIN + INIT _ THREAD is 3, constructing a first sub-THREAD by a THREAD () method, and then calling a THREAD. Constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread; judging the execution sequence of a main thread and a sub-thread through a return value of a getOrider () function, if the return value of the getOrider () protocol function is 0, executing a main thread task first, namely executing the onInitThread () protocol function first and then executing the onInitMain () protocol function, and if the return value of the getOrider () protocol function is 1, executing a sub-thread task first, namely executing the onInitMain () protocol function first and then executing the onInitThread () protocol function;
optionally, in a possible embodiment, the computer program 411 when executed by a processor implements the following steps: the MAIN THREAD and the sub THREAD execution order are determined by the return value of getOrider () only when the return value is INIT _ MAIN + INIT _ THREAD is 3, otherwise the return value of getOrider () is not processed, that is, the function return information of getOrider () is ignored, so that the initialization speed can be improved.
Then, the initialization operation of the controller object item corresponding to the initialization type of the sub thread in the first sub thread is realized by calling an item. And realizing the initialization operation of the controller object item corresponding to the initialization type of the main thread in the main thread by calling an item.
By acquiring the initialization logic type of the controller and then initializing the controller through the initialization register according to the initialization logic type, the controller with the sub-thread initialization logic type can be placed into the sub-thread for initialization, and the controller with the main thread initialization logic type is placed into the main thread for initialization, so that system crash caused by the fact that the controller with the main thread initialization logic type is placed into the sub-thread for initialization mistakenly can be avoided, and the stability of controller initialization is improved.
Optionally, in a possible embodiment, the computer program 411 when executed by a processor implements the following steps: for the initialization process of the controller with the initialization logic type of the sub-thread initialization type, the priority M of the controller can be obtained according to a preset priority strategy;
the preset priority policy can be automatically acquired from a local or server, or the priority policy manually selected by a user can be acquired, and the priority policy is used for determining the priority sequence when the controller is initialized.
Acquiring an urgency factor K of the controller, wherein the K is an integer between [10,100 ]; k represents the urgency degree of a task corresponding to the controller, and the larger the value of K is, the more urgent the task is, the task is to be executed preferentially;
obtaining a complexity factor B of the controller, wherein B is N Q, N is a natural number representing algorithm complexity, if N is 0, N is also assigned to be 1 to avoid occurrence of business logic abnormity, Q is an increasing factor influencing the complexity factor B and is used for increasing the influence degree of the complexity factor B, and Q is a positive number which is more than or equal to 1; and the complexity of the algorithm is used for evaluating the complexity of the algorithm used for processing the task, and the larger the number of the task complexity B is, the more complex the task corresponding to the controller is.
The priority M of the controller is calculated by the following formula:
m ═ T × K/B; t is an adjusting coefficient, is an integer between 1 and 100, and can be taken as the value according to specific situations. The M and the K, B form a square relation, so that the influence degree of the urgency factor K and the complexity factor B can be enlarged, the value range interval distribution of the M is more dispersed, and the priority M of different controllers can be distinguished conveniently at the later stage. Therefore, M is in proportion to K and in inverse proportion to B, namely, the higher the task urgency degree is, the task is processed with higher priority, the task complexity is higher, the task is processed with higher time, and the priority is set to be lower, so that the controllers corresponding to the tasks with high urgency degree and low complexity can be initialized with higher priority, and the controller initialization speed can be increased.
And initializing the controller through the initialization register according to the priority M of the controller.
Acquiring a first thread quantity factor Num1 according to the current system performance, wherein the system performance comprises system processor performance or system memory performance; for example, the first thread quantity factor Num1 is obtained by obtaining the size of the system memory, for example, if the system memory is less than or equal to 2G, it is determined as the low-end device, otherwise, it is determined as the high-end device. Constructing a mapping relation between system performance and thread quantity, wherein the specific mapping function design is as follows:
Num1=C*mem
where C is a tuning parameter and mem is the system memory capacity, the first thread count factor Num1 represents the total first thread count to be opened, the first thread count factor. Optionally, Num1 ranges from [1,10], taking the maximum value if it is outside the range interval.
Obtaining a second thread quantity factor Num2 according to the quantity of the controllers with the priority M greater than a preset value in the set object List;
and comparing the sizes of the first thread quantity factor Num1 and the second thread quantity factor Num2, and taking the larger value as the number Num of the main threads to be created.
Generating a corresponding number of main threads according to the number Num of the main threads;
and generating a sub-thread corresponding to the main thread according to the task information of the controller, and initializing the controller through the sub-thread.
The initialization List referenced in the collection object List is executed by opening up multiple threads. The method includes the steps that firstly, the number initNum of controllers needing initialization is obtained by calling a listinits size () method, then an integer X is obtained by calling the number initNum to divide Num, then X tasks are executed according to each thread, and optionally, if the number initNum is divided by Num to have a remainder, controllers corresponding to the remainder are all placed in the last thread to be initialized.
In each main thread, acquiring task information of a corresponding controller by a listinits.get (i) method, calling a start function in a thread pool to open up a sub-thread, and putting the acquired task in the opened sub-thread for processing. Therefore, tasks processed in the main thread can be completely switched to the sub-threads to be processed originally, functions of the non-main thread can be switched to instantiated sub-threads to be processed originally, and due to the fact that a plurality of sub-thread tasks are opened up, the purpose that a plurality of initialization processes are parallel can be achieved, and the initialization speed and stability of the controller are improved.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include such modifications and variations.

Claims (9)

1. A method of initializing a controller, comprising:
generating an initialization register, wherein the initialization register is used for managing and analyzing the controller needing initialization;
generating an initialization protocol, and realizing the unified processing of the initialization logic function of the controller through the initialization protocol;
registering the initialization protocol in the initialization register;
acquiring an initialization logic type of the controller according to the initialization protocol;
and initializing the controller through the initialization register according to the initialization logic type so as to place the controller with the sub-thread initialization logic type into the sub-thread for initialization and place the controller with the main thread initialization logic type into the main thread for initialization.
2. The method according to claim 1, wherein the initializing protocol specifically includes:
the initialization protocol is a public type protocol, and comprises 4 protocol functions: onInitThread (), onInitMain (), getType (), getOrder (); the onInitThread protocol function is a public protocol function, the return value is a void type, and the protocol function is subsequently used for executing the initialization service logic related to the sub-thread;
the access right and the return value type of the onInitMain protocol function are consistent with the onInitThread protocol function, and the onInitMain protocol function is subsequently used for executing the initialization service logic of the main thread;
the getType () protocol function of the function is public access right, the return value is int type, and the int type return value comprises three constants: INIT _ read is 1, INIT _ MAIN is 2, INIT _ MAIN + INIT _ read is 3; the return value of the getType function can only be the value of INIT _ THREAD or INIT _ MAIN + INIT _ THREAD, namely the return value of 1 indicates that the controller initialization logic type only has a sub-THREAD initialization logic type, the return value of 2 indicates that the controller initialization logic type only has a MAIN THREAD initialization logic type, and the return value of 3 indicates that the controller initialization logic type has both a sub-THREAD initialization logic type and a MAIN THREAD initialization logic type;
the getOrider () is a protocol function for controlling the execution sequence of the thread, and is used for controlling the sequence of executing the protocol function onInitMain () and the protocol function onInitThread (); if the getOrider () protocol function return value is 0, it means that the onInitThread () protocol function is executed first and then the onInitMain () protocol function is executed, and if the getOrider () protocol function return value is 1, it means that the onInitMain () protocol function is executed first and then the onInitThread () protocol function is executed.
3. The method according to claim 2, wherein the generating an initialization registrar specifically comprises:
generating an initialization register by an initialization register function; the addlnitregister function addInitRegister access right is a public right, the return value is a void type return value, and the initialization register comprises two access parameters: a parameter myInitHandler of the type of IInit protocol and a priority parameter M representing the controller;
defining a global collection object List for storing information of the initialization register data; and initializing the collection object List in the initialization register function.
4. The method of claim 3,
the generating an initialization register further comprises:
in the addlnitregster function, emptying the myInitHandler; if the myInitHandler is empty, returning the function addInitRegister through a return, otherwise, judging whether the myInitHandler is contained, if the myInitHandler is contained, terminating logic through a return statement, otherwise, adding the myInitHandler to the collection object List;
registering the initialization protocol in the initialization register specifically includes:
inheriting the initialization protocol by means of instantiations and overwriting the onInitThread (), onInitMain (), getType (), getOrder () protocol functions.
5. The method according to claim 4, wherein the obtaining the initialization logic type of the controller according to the initialization protocol specifically includes:
firstly, judging whether the listInit of the set object List is empty or not, and if the listInit of the set object List is empty, directly returning through a return statement so as to terminate an initialization process; if not, obtaining the number count of the controllers in the listInit set of the set object List through a listInit () function, if the count is 0, indicating that no controller needing initialization exists in the listInit set, and terminating the initialization process through return;
if the count is not 0, sequentially taking out the controller object items which need to be initialized in the listInit set in a traversal mode, wherein the controller object items conform to the definition of an InituUpdide protocol; by calling the getType () function in the controller object item, the size of the return value is judged, and the return value is one of the following three return values: the controller initialization logic type includes that INIT _ THREAD is 1, the controller initialization logic type only includes a sub-THREAD initialization logic type, INIT _ MAIN is 2, the controller initialization logic type only includes a MAIN THREAD initialization logic type, INIT _ MAIN + INIT _ THREAD is 3, and the controller initialization logic type includes both the sub-THREAD initialization logic type and the MAIN THREAD initialization logic type.
6. The method according to claim 5, wherein initializing the controller by the initialization register according to the initialization logic type specifically includes:
if the returned value of the getType () function is INIT _ THREAD equal to 1, constructing a first sub-THREAD, then calling a thread.start () function in the first sub-THREAD to start, and realizing the initialization operation of the controller object item in the first sub-THREAD by calling an item.ONINITThread () function;
if the returned value of the getType () function is INIT _ MAIN ═ 2, constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread, and then calling an item.onlntmain () function in a code block of the Runnable to realize the initialization operation of the controller object item in the main thread.
7. The method of claim 5, wherein initializing the controller with the initialization register according to the initialization logic type further comprises:
if the returned value of the getType () function is INIT _ MAIN + INIT _ THREAD which is 3, constructing a first sub-THREAD, and then calling a thread.start () function in the first sub-THREAD to start; constructing a thread switching object Handler through a Handler class provided in an Android system; calling a handler.post (new Runnable { }) function in the thread switch object handler to construct an execution Runnable in a main thread;
implementing an initialization operation of the controller object item corresponding to a sub-thread initialization type in the first sub-thread by calling an item.
And realizing the initialization operation of the controller object item corresponding to the initialization type of the main thread in the main thread by calling an item.
8. A controller initialization apparatus, comprising:
the initialization register generating unit is used for generating an initialization register which is used for managing and analyzing the controller needing initialization;
an initialization protocol generation unit, configured to generate an initialization protocol, where the initialization protocol is used to implement a unification process of an initialization logic function of the controller;
a registration unit configured to register the initialization protocol in the initialization register;
an initialization logic type obtaining unit, configured to obtain an initialization logic type of the controller according to the initialization protocol;
and the execution unit is used for initializing the controller through the initialization register according to the initialization logic type so as to place the controller with the sub-thread initialization logic type into the sub-thread for initialization and place the controller with the main thread initialization logic type into the main thread for initialization.
9. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any of claims 1-7.
CN201910603757.2A 2019-07-05 2019-07-05 Method and related device for initializing controller Active CN110308942B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910603757.2A CN110308942B (en) 2019-07-05 2019-07-05 Method and related device for initializing controller

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910603757.2A CN110308942B (en) 2019-07-05 2019-07-05 Method and related device for initializing controller

Publications (2)

Publication Number Publication Date
CN110308942A CN110308942A (en) 2019-10-08
CN110308942B true CN110308942B (en) 2021-11-26

Family

ID=68078187

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910603757.2A Active CN110308942B (en) 2019-07-05 2019-07-05 Method and related device for initializing controller

Country Status (1)

Country Link
CN (1) CN110308942B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1517868A (en) * 2003-01-08 2004-08-04 ������������ʽ���� Information processing device, method and program
CN103345422A (en) * 2013-07-02 2013-10-09 厦门雅迅网络股份有限公司 Multithreading hard real-time control method based on Linux
CN108121571A (en) * 2017-12-21 2018-06-05 郑州云海信息技术有限公司 A kind of individual reset design and realization based on system hardware module

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8607199B2 (en) * 2009-12-16 2013-12-10 International Business Machines Corporation Techniques for debugging code during runtime
US9043363B2 (en) * 2011-06-03 2015-05-26 Oracle International Corporation System and method for performing memory management using hardware transactions

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1517868A (en) * 2003-01-08 2004-08-04 ������������ʽ���� Information processing device, method and program
CN103345422A (en) * 2013-07-02 2013-10-09 厦门雅迅网络股份有限公司 Multithreading hard real-time control method based on Linux
CN108121571A (en) * 2017-12-21 2018-06-05 郑州云海信息技术有限公司 A kind of individual reset design and realization based on system hardware module

Also Published As

Publication number Publication date
CN110308942A (en) 2019-10-08

Similar Documents

Publication Publication Date Title
US20190324772A1 (en) Method and device for processing smart contracts
CN107463367B (en) Transition animation realization method and device
EP1582985A2 (en) Test case inheritance controlled via attributes
US20090106680A1 (en) Drag and drop object attribute assignment for objects in a graphical user interface (gui)
CN106874176B (en) Intelligent test method and device
JP2014504768A (en) Method, computer program product, and apparatus for progressively unloading classes using a region-based garbage collector
US20210149784A1 (en) Methods, systems, and media for initiating and monitoring instances of workflows
US7877749B2 (en) Utilizing and maintaining data definitions during process thread traversals
US20220214931A1 (en) System and method for exposing features of integration platform adapters as first-class actions in an orchestration template
CN117093352B (en) Template-based computing cluster job scheduling system, method and device
JP5005172B2 (en) Database management system and database management method
CN112667307A (en) Extension method and extension device based on el-tabs
CN111953503A (en) NFV resource deployment arrangement method and network function virtualization orchestrator
WO2019024305A1 (en) Message processing method and apparatus, electronic device and computer readable storage medium
US8935657B2 (en) Model-to-model transformation by kind
CN109783159A (en) Application starting method and apparatus based on configuration information
CN110308942B (en) Method and related device for initializing controller
CN106341469B (en) Loading method and device of tree node data
CN114730271A (en) Post-hoc image and volume viewing of short-term Linux containers
CN110321175B (en) Controller initialization method and related device
CN109032572B (en) Method for Java program method internal connection based on byte code
CN112699042B (en) Unit test case generation method and device
CN109150993B (en) Method for obtaining network request tangent plane, terminal device and storage medium
CN113326077A (en) Configuration file loading method and device
JPH03184123A (en) Procedure state description element system for digital data processor

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
GR01 Patent grant
GR01 Patent grant