目录

Thread 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:

  • 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.