harmony 鸿蒙Thread Model (Stage Model)
Thread Model (Stage Model)
A thread is the basic unit for the operating system to perform computing and scheduling. It is an execution flow within a process and shares the resources of the process. A process can contain multiple threads.
Thread Type
There are three types of threads in the stage model: - Main thread - Draws the UI. - Manages the ArkTS engine instance of the main thread so that multiple UIAbility components can run on it. - Manages ArkTS engine instances of other threads, for example, using TaskPool to create or cancel tasks, and starting and terminating Worker threads. - Distributes interaction events. - Processes application code callbacks (event processing and lifecycle management). - Receives messages sent by the TaskPool and Worker threads. - TaskPool Thread
Used for time-consuming operations and provides APIs for setting the scheduling priority and load balancing. It is recommended. - Worker Thread
Used for time-consuming operations and supports inter-thread communication. For details about the operation mechanism, communication method, and usage of TaskPool and Worker, see Comparison Between TaskPool and Worker.
NOTE
- TaskPool manages the number of threads that can be created and their lifecycle. However, you need to maintain the lifecycle of Worker threads.
- Multiple components can exist in the same thread. For example, both UIAbility and UI components exist in the main thread. In the stage model, EventHub is used for data communication.
- To view thread information about an application process, run the hdc shell command to enter the shell CLI of the device, and then run the ps -p <pid> -T command, where <pid> indicates the process ID of the application.
Using EventHub for Intra-Thread Communication
EventHub provides APIs for sending and processing events in threads, including subscribing to, unsubscribing from, and triggering events. Using EventHub for Data Synchronization describes the development procedure by using data synchronization between the UIAbility component and the UI as an example.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Obtaining Reasons for Abnormal Application Exits
harmony 鸿蒙UIAbility Backup and Restore
harmony 鸿蒙Using Explicit Want to Start an Application Component
harmony 鸿蒙Introduction to Ability Kit
harmony 鸿蒙AbilityStage Component Container
harmony 鸿蒙Accessing a DataAbility
harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model
harmony 鸿蒙Common action and entities Values (Not Recommended)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦