CN117648165A - Application cold start task management method, device and system - Google Patents
Application cold start task management method, device and system Download PDFInfo
- Publication number
- CN117648165A CN117648165A CN202311671540.8A CN202311671540A CN117648165A CN 117648165 A CN117648165 A CN 117648165A CN 202311671540 A CN202311671540 A CN 202311671540A CN 117648165 A CN117648165 A CN 117648165A
- Authority
- CN
- China
- Prior art keywords
- task
- tasks
- application
- class
- scheduling
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000007726 management method Methods 0.000 title claims abstract description 85
- 238000000034 method Methods 0.000 claims abstract description 69
- 238000010586 diagram Methods 0.000 claims description 21
- 125000002015 acyclic group Chemical group 0.000 claims description 11
- 238000004590 computer program Methods 0.000 claims description 6
- 230000002159 abnormal effect Effects 0.000 claims description 3
- 230000006870 function Effects 0.000 claims description 3
- 230000008569 process Effects 0.000 abstract description 32
- 238000013461 design Methods 0.000 description 5
- 230000000694 effects Effects 0.000 description 5
- 230000008901 benefit Effects 0.000 description 2
- 230000008878 coupling Effects 0.000 description 2
- 238000010168 coupling process Methods 0.000 description 2
- 238000005859 coupling reaction Methods 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 238000009877 rendering Methods 0.000 description 2
- 238000006467 substitution reaction Methods 0.000 description 2
- 101150039208 KCNK3 gene Proteins 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000000903 blocking effect Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000000593 degrading effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000011423 initialization method Methods 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
- 238000002360 preparation method Methods 0.000 description 1
- 230000004043 responsiveness Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/4401—Bootstrapping
- G06F9/4403—Processor initialisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/5038—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/48—Indexing scheme relating to G06F9/48
- G06F2209/484—Precedence
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5021—Priority
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The invention relates to an application cold start task management method, device and system, which are used for creating a task which needs to be initialized in an application start stage as a task in a project; creating a task group management class to manage tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks; starting tasks through the task group management class mark, and executing all tasks in the task group; determining the sequence of executing tasks according to the priority, the front dependency and the rear dependency of the tasks by adopting a strategy scheduling class, and scheduling the tasks; and when all the tasks are executed, the task group management class marks the ending task and ends the task group. The method and the device realize unified management of the application initialization tasks, and uniformly process the dependency relationship among the tasks, so that the whole initialization process is concise and clear, the purpose of improving the application starting speed is achieved, and the application performance is improved.
Description
Technical Field
The present invention relates to the field of mobile applications, and in particular, to a method, an apparatus, and a system for managing an application cold start task.
Background
Cold start refers to the process of loading all necessary resources from scratch and performing the necessary initialization operations when a user first opens an application.
The cold start process for the android application comprises the following steps:
(1) The user triggers a clicking operation, and when the user clicks the application icon, the system receives a corresponding triggering event. The system creates a new process for the application to run the application.
(2) After the application process is created, the initialization operation of the application, including loading the code, library file, resource, etc. of the application, is started. At the same time, the application also performs some necessary configuration and initialization, such as setting application theme, language, authority, etc.
(3) After the application is initialized, the system invokes an entry point (e.g., activity) of the application to display a launch interface, typically a welcome page of the application or an application-tagged interface. At this point, the UI component of the application begins rendering and displaying on the screen.
In general, the cold start process of an android application is divided into three steps: creating a process, starting an application and drawing an interface. The process of creating and loading a process by a system generally cannot directly interfere in the whole process, so that in the process of starting an application, a process from starting a main process to starting a main interface is focused.
Referring to fig. 1, a cold start process schematic diagram of an android Application, an Application's attchbasecontext is counted as a start time point, and an Application's main page MainActivity's windowfoucsChanged method is counted as a start end time point. The main discussion of optimizing Application start-up time here is how to shorten the time from Application's attchbasecontext trigger to the MainActivity's ontdowwoucschanged method.
The existing initialization schemes at present have the following two types:
the first scheme is that all the initialization operations of the SDKs are sequentially executed in an onCreate method of Application. The scheme has no optimization effect on application starting, and if more time-consuming tasks are needed during starting, the starting time is too long.
In the second scheme, task asynchronous initialization and delay initialization are performed in a sub-thread of a time-consuming initialization Task scheme, and some tasks which are not necessarily initialized immediately are performed with delay initialization operation, so that the effect of optimizing the starting speed of an application can be achieved, but a huge application often needs initialization operation with a large number of SDKs and time-consuming tasks, the tasks may have interdependencies, and if unified management is not adopted for the tasks, the whole initialization flow is quite complicated along with the increase of the number of the initialization tasks.
Disclosure of Invention
In view of the shortcomings of the prior art, the invention aims to provide an application cold start task management method, device and system, which aim to improve the start speed of application cold start and improve application performance.
In a first aspect, the present application provides an application cold-start task management method, including:
creating a task to be initialized in an application starting stage as a task in a project, and presetting a priority for the task and attribute information of whether asynchronous initialization is needed;
creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks;
starting tasks through the task group management class marks, and executing all tasks in the task group;
determining the sequence of task execution according to the priority, the front dependency and the rear dependency of the task by adopting a strategy scheduling class, and scheduling the task according to the sequence of execution;
and when all the tasks are executed, the task group management class marks the ending task and ends the task group.
Optionally, determining the execution sequence of the tasks according to the priority, the pre-dependency and the post-dependency of the tasks includes:
generating a directed acyclic tree structure diagram according to the front dependency relationship and the rear dependency relationship among the tasks, and determining the sequence of executing the tasks based on the directed acyclic tree structure diagram;
wherein, the directed means that the task chain has definite starting and ending nodes, the acyclic means that each node has a dependency relationship in the structure diagram, but no ring-shaped dependency exists; the lines between each task represent the execution sequence, the front-end dependency relationship and the rear-end dependency relationship of each task, and the attribute information of whether asynchronous initialization is needed between the tasks is marked by adopting an identifier.
Optionally, the method further comprises: and encapsulating the strategy scheduling class by adopting a project management class, and providing a unified interface for calling an external interface.
Optionally, determining the order of execution of the tasks according to the priority, the pre-dependency and the post-dependency of the tasks by using the policy scheduling class, and scheduling the tasks according to the order of execution further includes:
and recording the task running state by adopting a task state class, wherein the task running state is used for identifying the current task under which state the task is executed.
Optionally, determining the order of execution of the tasks according to the priority, the pre-dependency and the post-dependency of the tasks by using the policy scheduling class, and scheduling the tasks according to the order of execution further includes:
and executing the tasks arranged after the current task according to the priority, the pre-dependency and the post-dependency when the running state of the current task shows the abnormal state.
Optionally, the method further comprises: and scheduling the asynchronous tasks by adopting a thread pool.
Optionally, the scheduling the asynchronous task by using the thread pool includes the following steps:
creating a thread pool, wherein the thread pool comprises a group of threads for executing tasks;
submitting asynchronous tasks to a thread pool, wherein the tasks are expressed in the form of task objects or functions, and the thread pool allocates an idle thread for each task to execute;
when a task is submitted, the thread pool selects an idle thread to execute the task; if there are no free threads in the thread pool, the task is placed in the wait queue until a thread is available;
once the task is complete, the thread returns to the thread pool and prepares to execute the next task; the thread pool will continue to fetch tasks from the wait queue to be performed and assign to available threads.
In a second aspect, the present application further provides an application cold-start task management device, including:
the creation module is configured to create a task which needs to be initialized in an application starting stage as a task in a project, and preset priorities for the tasks and attribute information of whether asynchronous initialization is needed or not; creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks;
the execution starting module is configured to start tasks through the task group management class mark and execute all tasks in the task group;
the scheduling module is configured to adopt a strategy scheduling class, determine the sequence of the tasks according to the priority, the front dependency relationship and the rear dependency relationship of the tasks, and schedule the tasks according to the sequence of the tasks;
and the execution ending module is configured to mark the ending task by the task group management class and end the task group when all the tasks are executed.
In a third aspect, the present application further provides an application cold-start task management system, including:
at least one processor; and
at least one memory storing a computer program;
wherein the computer program, when executed by the at least one processor, causes the application cold-start task management system to perform the steps of the application cold-start task management method according to any one of the above.
The invention has the following beneficial effects:
the application cold start task management method provided by the invention is used for creating the task to be initialized in the application start stage as the task in the project, and presetting the priority for the task and the attribute information of whether asynchronous initialization is needed; creating a task group management class to manage tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks; starting tasks through the task group management class mark, and executing all tasks in the task group; determining the sequence of task execution according to the priority, the front dependency and the rear dependency of the task by adopting a strategy scheduling class, and scheduling the task according to the sequence of execution; and when all the tasks are executed, the task group management class marks the ending task and ends the task group. The method and the device realize unified management of the application initialization tasks, and uniformly process the dependency relationship among the tasks, so that the whole initialization process is concise and clear, the purpose of improving the application starting speed is achieved, and the application performance is improved. In addition, the application cold start task management device and system with the technical effects are further provided.
Drawings
The drawings are only for purposes of illustrating particular embodiments and are not to be construed as limiting the invention, like reference numerals being used to refer to like parts throughout the several views. It is apparent that the drawings in the following description are only some of the embodiments described in the embodiments of the present invention, and that other drawings may be obtained from these drawings by those of ordinary skill in the art.
FIG. 1 is a schematic diagram of a cold start process for an android application;
FIG. 2 is a flowchart of one embodiment of the application cold start task management method provided herein;
FIG. 3 is a schematic diagram of a directed acyclic tree structure provided herein;
FIG. 4 is a process flow diagram of scheduling asynchronous tasks using a thread pool;
FIG. 5 is a schematic diagram of another embodiment of the application cold start task management method provided in the present application;
FIG. 6 is a schematic diagram of a system startup process according to another embodiment of the present application of a cold-start task management method;
FIG. 7 is a block diagram of an application cold start task management device provided herein;
fig. 8 is a block diagram of a structure of an application cold-start task management system provided in the present application.
Detailed Description
In order to make the technical solutions of the embodiments of the present invention better understood by those skilled in the art, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments. It should be understood that the description is only illustrative and is not intended to limit the scope of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, shall fall within the scope of the invention.
In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
In the description of the present invention, it should be noted that unless explicitly stated and limited otherwise, the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, are merely for convenience in describing the present invention and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a specific orientation, be configured and operated in a specific orientation, and thus should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. The terms "mounted," "connected," "coupled," and "connected" are to be construed broadly, and may be, for example, fixedly connected, detachably connected, or integrally connected; can be mechanically or electrically connected; can be directly connected or indirectly connected through an intermediate medium, and can be communication between two elements. The specific meaning of the above terms in the present invention will be understood in specific cases by those of ordinary skill in the art.
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the invention. Rather, they are merely examples of methods and systems that are consistent with aspects of the invention as detailed in the accompanying claims.
The present application provides an application cold start task management method, as shown in a flowchart of a specific embodiment of the application cold start task management method provided in fig. 2, where the method specifically includes:
s101: creating a task to be initialized in an application starting stage as a task in a project, and presetting a priority for the task and attribute information of whether asynchronous initialization is needed;
each initialization Task is abstracted into a Task (Task). And, according to the importance, urgency and influence scope of the task, corresponding priority is allocated to each task, and the higher the importance, the higher the urgency and the wider the influence scope, the higher the corresponding priority is.
Whether or not asynchronous initialization is required between tasks refers to whether or not initialization operations need to be performed in an asynchronous manner between different tasks (or threads) in an application. In application development, some initialization operations may be time consuming, such as network requests, database connections, resource loading, etc. If these initialization operations are performed in the main thread (UI thread), the operation of the main thread is blocked, resulting in an application incapable of responding to the user's interactive operation, thereby degrading the user experience. To avoid blocking the main thread, these time-consuming initialization operations may be chosen to be performed in a background thread (sub-thread), i.e. asynchronous initialization is used. With asynchronous initialization, the host thread can continue to process user input and interface rendering without being affected by the initialization operation. Asynchronous initialization may be implemented in a variety of ways, such as using threads, handler, asyncTask, rxJava, coroutines, etc. The specific choice of which way depends on the needs of the developer and the technology stack.
S102: and creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks.
And the task group management class is used for uniformly managing all tasks, processing the dependency relationship and the sequence of execution of the tasks and being responsible for managing and coordinating the execution of the tasks.
The task group management class can be created through a factory mode, each task can be created through abstracting an interface, and the task group management class cooperates with the interface to realize the creation of specific tasks. The task creation process can be encapsulated in a specific task factory class by using a factory mode, and the task group management class creates a specific task object by calling a factory class method. This has the advantage that the task group management class does not need to be concerned with the creation details of a specific task, but only relies on the task factory interface for the creation and management of the task. By abstracting the task factory interface, polymorphism of tasks can be realized, allowing different types of tasks to be created and executed in the task group management class. The design mode enables codes to be more flexible and high in expandability, and the coupling degree between the codes can be well reduced.
The task group management class creates concrete task objects through a factory model, and the creation of each task can be realized through an abstract task factory interface. The design method can improve flexibility, expandability and maintainability of codes and reduce the coupling degree between codes.
Dividing tasks into different task groups refers to dividing a group of related tasks into different task groups for better management and distribution of tasks. Specifically, the division can be performed specifically according to the combination of factors such as the type of the task, the complexity of the task, the dependency relationship between the tasks, the availability of resources and the like, and the adjustment can be performed in combination with specific situations.
S103: starting tasks through the task group management class marks, and executing all tasks in the task group;
the task group management class marks the start task, which means that the state of one task is set to an operation that has already started to be executed or in progress. By marking the start of a task, a signal can be communicated to the relevant person that the task is initiated and indicates that the task has entered the active phase.
S104: determining the sequence of task execution according to the priority, the front dependency and the rear dependency of the task by adopting a strategy scheduling class, and scheduling the task according to the sequence of execution;
generating a directed acyclic tree structure diagram according to the front dependency relationship and the rear dependency relationship among the tasks, and determining the sequence of executing the tasks based on the directed acyclic tree structure diagram. Wherein, the directed means that the task chain has definite starting and ending nodes, the acyclic means that each node has a dependency relationship in the structure diagram, but no ring-shaped dependency exists; the lines between each task represent the execution sequence, the front-end dependency relationship and the rear-end dependency relationship of each task, and the attribute information of whether asynchronous initialization is needed between the tasks is marked by adopting an identifier.
Referring to fig. 3, a schematic diagram of a directed acyclic tree structure diagram is provided, in the tree structure, start and end respectively represent a start node and an end node of a start Task, task1 to Task7 respectively represent tasks to be initialized in an application start process, and lines between each Task represent execution sequence and association relation of each Task. Task1, task3, task5, task7 represent tasks requiring synchronous initialization, task2, task4, task6 represent tasks requiring asynchronous initialization, wherein Task7 represents tasks that can release application starting activity (launchlactivity) without initialization, which means that in the process of Task initialization, not all tasks are initialized to start launchlactivity, and only some specific tasks need to be initialized to directly pull up launchlactivity, thereby improving the application starting speed.
And scheduling tasks (tasks) according to different strategies through a strategy scheduling class.
S105: and when all the tasks are executed, the task group management class marks the ending task and ends the task group.
After the task is executed, the task is finished through marking, and the execution condition of the task can be specifically marked and classified so as to be convenient for tracking and management.
The application cold start task management method provided by the invention is used for creating the task to be initialized in the application start stage as the task in the project, and presetting the priority for the task and the attribute information of whether asynchronous initialization is needed; creating a task group management class to manage tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks; starting tasks through the task group management class mark, and executing all tasks in the task group; determining the sequence of task execution according to the priority, the front dependency and the rear dependency of the task by adopting a strategy scheduling class, and scheduling the task according to the sequence of execution; and when all the tasks are executed, the task group management class marks the ending task and ends the task group. The method and the device realize unified management of the application initialization tasks, and uniformly process the dependency relationship among the tasks, so that the whole initialization process is concise and clear, the purpose of improving the application starting speed is achieved, and the application performance is improved.
On the basis of any one of the foregoing embodiments, the method provided by the present application may further include: and encapsulating the strategy scheduling class by adopting a project management class, and providing a unified interface for calling an external interface.
The project management class is adopted to package the strategy scheduling class and provide a uniform interface for calling the outside, so that the advantages of abstraction, packaging, uniform interface, expandability, hiding of internal details and the like can be brought. The design method is helpful for simplifying the code logic of an external calling party and improving the maintainability and the expandability of the system.
On the basis of any one of the foregoing embodiments, the method provided by the present application may further include: and recording the task running state by adopting a task state class, wherein the task running state is used for identifying the current task under which state the task is executed. And executing the tasks arranged after the current task according to the priority, the front dependency and the rear dependency according to the end of the execution of the current task when the running state of the current task shows an abnormal state.
The running state of the task is recorded through the task state class, and the whole execution process of the task can be tracked and monitored. By the aid of the method, real-time knowledge of task execution conditions can be provided, potential problems can be found and solved in time, and stability and reliability of the system are improved.
On the basis of any one of the foregoing embodiments, the method provided by the present application may further include: and scheduling the asynchronous tasks by adopting a thread pool. It should be understood that, in this embodiment, an asynchronous task refers to a task that needs to be asynchronously initialized and divided into an asynchronous task group. By marking the initialization operation asynchronous, it can be made to execute in the background and the program can continue to respond to other tasks or user operations without waiting for completion of the initialization operation.
As shown in the process flow chart of scheduling asynchronous tasks by using a thread pool in fig. 4, the scheduling of asynchronous tasks by using the thread pool specifically includes the following steps:
s201: creating a thread pool, wherein the thread pool comprises a group of threads for executing tasks;
s202: submitting asynchronous tasks to a thread pool, wherein the tasks are expressed in the form of task objects or functions, and the thread pool allocates an idle thread for each task to execute;
s203: when a task is submitted, the thread pool selects an idle thread to execute the task; if there are no free threads in the thread pool, the task is placed in the wait queue until a thread is available;
s204: once the task is complete, the thread returns to the thread pool and prepares to execute the next task; the thread pool will continue to fetch tasks from the wait queue to be performed and assign to available threads.
Scheduling asynchronous tasks with thread pools may provide concurrency performance enhancements, resource control and constraints, increased responsiveness and user experience, task scheduling and management, and uniform resource sharing. This design can effectively manage and handle a large number of asynchronous tasks and provide better system performance and user experience.
A specific procedure of another specific embodiment of applying the cold start task management method provided in the present application is described below with reference to fig. 5.
The specific names and descriptions of the classes referred to therein refer to table 1.
TABLE 1
Wherein, the class design thinking is as follows:
(1) task: defining basic attributes of tasks, wherein the basic attributes can include, but are not limited to, priority, whether asynchronous initialization is needed, execution state and the like; a management set of pre-dependency and post-dependency of a current task is defined, and methods are provided to add and delete these dependencies.
(2) TaskState: the states of several tasks during execution are defined, so that it is convenient to schedule tasks and select strategies under which state the current task is executed, for example, the states of pending (pending), running (running), completed (failed) and the like can be defined.
(3) Project: a set of tasks (tasks) is managed, providing flag bits indicating the start and end of a Task stream. Additionally, a method of starting a task group may also be included.
(4) Project. Builder: for building Project, methods are provided to add tasks and define dependencies between tasks. Methods of constructing the final project object (e.g., build ()) may also be included.
(5) Project. Task factor: a method of creating a Task object is provided, and a template method mode or a factory method mode may be used.
(6) ITaskCreator: an abstract interface, defining the method of creating the task. May be implemented by specific classes that cooperate with project.
(7) TaskRuntime: and the policy scheduling class defines a policy scheduling method and is responsible for scheduling tasks according to different policies. An appropriate execution strategy can be selected according to the information such as the priority, the state and the like of the task.
(8) TaskFlowManager: and an external high-level interface encapsulates the TaskRuntime, so that a user only needs to interact with the TaskFlowManager.
Referring to the system start-up process schematic of fig. 6, at system start-up, tasks are performed as follows:
s301: the construction stage is as follows: project instances are built by using Project. Builder, and all Task instances and their dependency relationships are defined. Specific Task instances are created using project.
S302: the preparation stage: all tasks are initially in the PENDING state. And setting the front-end task and the rear-end task according to the defined dependency relationship.
S303: scheduling: tasks are started using the TaskFlowManager. The taskflow manager calls a taskrun scheduling method, and selects an appropriate strategy to schedule the task according to the state of the task and other parameters.
S304: the execution stage: the Task RUNNING processes execution of each Task, and when all the pre-tasks are in the complete state, the current Task can enter the RUNNING state. If a task fails to execute, it becomes a FAILED state and affects the post-tasks that depend on the task.
S305: the completion stage: the task is marked as complete once COMPLETED. When all tasks have been completed or some tasks have been terminated by errors, the entire task flow ends.
In the above flow, the taskrun is the core scheduler responsible for the decisions at runtime. The Project organizes the tasks into a Directed Acyclic Graph (DAG) and provides methods to launch and manage the tasks. The TaskFlowManager hides the complexity from the outside, allowing clients to initiate and manage task flows through a simple interface.
The method introduces the concept of task groups, performs unified management on a group of tasks, and orderly manages the prior disordered initialization tasks. The task priority processing and front-end and rear-end task schemes can simplify the task initialization method and avoid unnecessary initialization operation, so that the application starting is quickened to a certain extent. In addition, by adding task scheduling policy management, different tasks are executed according to different policies. Thread management of asynchronous tasks may also be achieved through thread pool scheduling.
In addition, the application further provides an application cold start task management device, as shown in a structural block diagram of the application cold start task management device provided in fig. 7, the device specifically includes:
a creation module 100 configured to create a task to be initialized at an application start stage as a task in a project, set a priority for the task in advance, and attribute information whether asynchronous initialization is required; creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks;
an execution start module 200 configured to start tasks through the task group management class flag, and execute all tasks in a task group;
the scheduling module 300 is configured to determine the sequence of execution of the tasks according to the priority, the pre-dependency and the post-dependency of the tasks by adopting a strategy scheduling class, and schedule the tasks according to the sequence of execution;
the execution end module 400 is configured to mark the end task by the task group management class and end the task group when all the tasks are executed.
In addition, the application further provides an application cold start task management system, as shown in a structural block diagram of the application cold start task management system provided in fig. 8, where the system specifically includes: at least one processor 1; and at least one memory 2 in which a computer program is stored; wherein the computer program, when executed by the at least one processor 1, causes the application cold-start task management system to perform the steps of the application cold-start task management method according to any of the above.
The method and the device realize unified management of the application initialization tasks, and uniformly process the dependency relationship among the tasks, so that the whole initialization process is concise and clear, the purpose of improving the application starting speed is achieved, and the application performance is improved.
Finally, it should be noted that the above embodiments are merely for illustrating the technical solution of the embodiments of the present invention, and are not limiting. Although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the embodiments of the invention, and any changes and substitutions that would be apparent to one skilled in the art are intended to be included within the scope of the present invention.
Claims (9)
1. An application cold start task management method, comprising:
creating a task to be initialized in an application starting stage as a task in a project, and presetting a priority for the task and attribute information of whether asynchronous initialization is needed;
creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks;
starting tasks through the task group management class marks, and executing all tasks in the task group;
determining the sequence of task execution according to the priority, the front dependency and the rear dependency of the task by adopting a strategy scheduling class, and scheduling the task according to the sequence of execution;
and when all the tasks are executed, the task group management class marks the ending task and ends the task group.
2. The method for managing the application cold start task according to claim 1, wherein determining the execution sequence of the tasks according to the priorities, the pre-dependencies and the post-dependencies of the tasks comprises:
generating a directed acyclic tree structure diagram according to the front dependency relationship and the rear dependency relationship among the tasks, and determining the sequence of executing the tasks based on the directed acyclic tree structure diagram;
wherein, the directed means that the task chain has definite starting and ending nodes, the acyclic means that each node has a dependency relationship in the structure diagram, but no ring-shaped dependency exists; the lines between each task represent the execution sequence, the front-end dependency relationship and the rear-end dependency relationship of each task, and the attribute information of whether asynchronous initialization is needed between the tasks is marked by adopting an identifier.
3. The application cold start task management method according to claim 1, further comprising: and encapsulating the strategy scheduling class by adopting a project management class, and providing a unified interface for calling an external interface.
4. The method for managing the application cold start task according to claim 1, wherein the determining the execution sequence of the tasks according to the priorities, the pre-dependencies and the post-dependencies of the tasks by using the policy scheduling class, and the scheduling the tasks according to the execution sequence further comprises:
and recording the task running state by adopting a task state class, wherein the task running state is used for identifying the current task under which state the task is executed.
5. The method for managing the application cold start task according to claim 1, wherein the determining the execution sequence of the tasks according to the priorities, the pre-dependencies and the post-dependencies of the tasks by using the policy scheduling class, and the scheduling the tasks according to the execution sequence further comprises:
and executing the tasks arranged after the current task according to the priority, the pre-dependency and the post-dependency when the running state of the current task shows the abnormal state.
6. The application cold start task management method according to any one of claims 1 to 5, further comprising: and scheduling the asynchronous tasks by adopting a thread pool.
7. The method for managing tasks for cold start of an application according to claim 6, wherein said scheduling asynchronous tasks using a thread pool comprises the steps of:
creating a thread pool, wherein the thread pool comprises a group of threads for executing tasks;
submitting asynchronous tasks to a thread pool, wherein the tasks are expressed in the form of task objects or functions, and the thread pool allocates an idle thread for each task to execute;
when a task is submitted, the thread pool selects an idle thread to execute the task; if there are no free threads in the thread pool, the task is placed in the wait queue until a thread is available;
once the task is complete, the thread returns to the thread pool and prepares to execute the next task; the thread pool will continue to fetch tasks from the wait queue to be performed and assign to available threads.
8. An application cold start task management device, comprising:
the creation module is configured to create a task which needs to be initialized in an application starting stage as a task in a project, and preset priorities for the tasks and attribute information of whether asynchronous initialization is needed or not; creating a task group management class to manage the tasks, dividing the tasks into different task groups, and building a front-end dependency relationship and a rear-end dependency relationship between the tasks;
the execution starting module is configured to start tasks through the task group management class mark and execute all tasks in the task group;
the scheduling module is configured to adopt a strategy scheduling class, determine the sequence of the tasks according to the priority, the front dependency relationship and the rear dependency relationship of the tasks, and schedule the tasks according to the sequence of the tasks;
and the execution ending module is configured to mark the ending task by the task group management class and end the task group when all the tasks are executed.
9. An application cold-start task management system, comprising:
at least one processor; and
at least one memory storing a computer program;
wherein the computer program, when executed by the at least one processor, causes the application cold-start task management system to perform the steps of the application cold-start task management method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311671540.8A CN117648165A (en) | 2023-12-07 | 2023-12-07 | Application cold start task management method, device and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311671540.8A CN117648165A (en) | 2023-12-07 | 2023-12-07 | Application cold start task management method, device and system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117648165A true CN117648165A (en) | 2024-03-05 |
Family
ID=90043091
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311671540.8A Pending CN117648165A (en) | 2023-12-07 | 2023-12-07 | Application cold start task management method, device and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117648165A (en) |
-
2023
- 2023-12-07 CN CN202311671540.8A patent/CN117648165A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10223166B2 (en) | Scheduling homogeneous and heterogeneous workloads with runtime elasticity in a parallel processing environment | |
CN113535367B (en) | Task scheduling method and related device | |
US7406699B2 (en) | Enhanced runtime hosting | |
CN102567090B (en) | The method and system of execution thread is created in computer processor | |
JP2011070256A (en) | Debugger and program | |
CN112363913B (en) | Parallel test task scheduling optimizing method, device and computing equipment | |
CN113254240B (en) | Method, system, device and medium for managing control device | |
CN117093352B (en) | Template-based computing cluster job scheduling system, method and device | |
RU2494446C2 (en) | Recovery of control of processing resource, which performs external context of execution | |
CN108614697B (en) | Background Dex compiling control method and device | |
CN117252559A (en) | Business process processing method, device, computer equipment and storage medium | |
CN117076096A (en) | Task flow execution method and device, computer readable medium and electronic equipment | |
CN114911538B (en) | Starting method of running system and computing equipment | |
CN115658278B (en) | Micro-task scheduler supporting high concurrency protocol interaction | |
CN111651279A (en) | Method and system for processing business process | |
CN117648165A (en) | Application cold start task management method, device and system | |
CN112506655B (en) | Drawing method, storage medium and application server | |
US10713085B2 (en) | Asynchronous sequential processing execution | |
CN117931483B (en) | Operating system, generating method, electronic device, storage medium, and program product | |
US20230393889A1 (en) | Multi-core processor, multi-core processor processing method, and related device | |
JP2002297402A (en) | Digital device, task management method and program therefor | |
CN114911539A (en) | Starting method of running system and computing equipment | |
CN117827401A (en) | Asynchronous Android starting task scheduling method | |
CN113094167A (en) | Cloud computing resource processing method, device, equipment and storage medium | |
CN115454590A (en) | Activity graph-oriented simulation scheduling method and system |
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 |