harmony 鸿蒙Thread Model Overview (Stage Model)

  • 2023-02-03
  • 浏览 (700)

Thread Model Overview (Stage Model)

For an OpenHarmony application, each process has a main thread to provide the following functionalities:

  • Draw the UI.
  • Manage the ArkTS engine instance of the main thread so that multiple UIAbility components can run on it.
  • Manage ArkTS engine instances of other threads, for example, starting and terminating other threads.
  • Distribute interaction events.
  • Process application code callbacks (event processing and lifecycle management).
  • Receive messages sent by the worker thread.

In addition to the main thread, there is an independent thread, named worker. The worker thread is mainly used to perform time-consuming operations. The worker thread is created in the main thread and is independent from the main thread. It cannot directly operate the UI. A maximum of eight worker threads can be created. thread-model-stage

Based on the OpenHarmony thread model, different services run on different threads. Service interaction requires inter-thread communication. In the same process, threads can communicate with each other in Emitter or Worker mode. Emitter is mainly used for event synchronization between threads, and Worker is mainly used to execute time-consuming tasks.

NOTE

  • The stage model provides only the main thread and worker thread. Emitter is mainly used for event synchronization within the worker thread or between the main thread and worker thread.
  • The UIAbility and UI are in the main thread. For details about data synchronization between them, see Data Synchronization Between UIAbility and UI.
  • 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 -T command, where indicates the process ID of the application.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Application Models

harmony 鸿蒙Using Explicit Want to Start an Application Component

harmony 鸿蒙Using Implicit Want to Open a Website

harmony 鸿蒙AbilityStage Component Container

harmony 鸿蒙Accessing a DataAbility

harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙Common action and entities Values

harmony 鸿蒙API Switching Overview

harmony 鸿蒙Switching of app and deviceConfig

0  赞