| Files | Last commit | Last update |
|---|---|---|
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 8 months ago | ||
| 1 year ago | ||
| 8 months ago | ||
| 8 months ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago |
App Concurrency Design
Overview
This sample demonstrates the design of app concurrency, including sample code for the recommended solutions covered in the corresponding best practice. You can learn about multi-device development by referring to the source code.
Effect

Project Directory
├──entry/src/main/cpp
│ ├──types/libndkDrawing
│ │ ├──Index.d.ts
│ │ └──oh-package.json5
│ ├──CMakeLists.txt
│ └──native_bridge.cpp // Native-side exposed drawing interface nativeOnDraw for frontend invocation
├──entry/src/main/ets // Code
│ ├──entryability
│ │ └──EntryAbility.ets // Entry ability
│ ├──entrybackupability
│ │ └──EntryBackupAbility.ets
│ ├──pages
│ │ ├──ConcurrencyCapabilitySelection1.ets // Time-consuming task concurrency
│ │ ├──ConcurrencyCapabilitySelection2.ets // Continuous task concurrency
│ │ ├──ConcurrentTaskManagement1.ets // Multi-task execution (serial dependency)
│ │ ├──ConcurrentTaskManagement2.ets // Multi-task execution (tree dependency)
│ │ ├──ConcurrentTaskManagement3.ets // Multi-task result sync (task group)
│ │ ├──ConcurrentTaskManagement4.ets // Multi-task priority scheduling
│ │ ├──ConcurrentTaskManagement5.ets // Delayed task scheduling
│ │ ├──Demo.ets
│ │ ├──freezeObj.ts
│ │ ├──InterThreadCommunication1.ets // Cross-language thread communication (C++ and ArkTS)
│ │ ├──InterThreadCommunication2.ets // Inter-thread module sharing (singleton mode) (solution 1)
│ │ ├──InterThreadCommunication3.ets // Inter-thread module sharing (singleton mode)
│ │ └──InterThreadCommunication4.ets // Inter-thread immutable data sharing
│ └──workers
│ └──Worker.ets // Inter-thread immutable data sharing
└──entry/src/main/resources // App resources
How to Use
- Tap Scenarios for concurrent execution of time-consuming tasks. The console prints Return:3.
- Tap Scenarios of concurrent execution of long-duration tasks. The console prints execute success.
- Tap Multi-tasking concurrent execution (serial sequential dependency). The console prints result is abc.
- Tap Multi-task concurrent execution (tree-like dependency). The console prints taskpool:: execute task3 res: "100", taskpool:: execute task2 res: 200, and taskpool:: execute task1 res: 300.
- Tap Multi-task synchronous waiting for results (task group). The console prints res: followed by the corresponding result.
- Tap Multi-task priority scheduling. The console prints execColorInfo success.
- Tap Task Delay Scheduling. The console prints taskpool result: 100.
- Tap Cross-language multithreaded communication (C++ and ArkTS). The console prints click nativeCall success.
- Tap Inter-thread module sharing (Singleton pattern) (Solution 1). The console prints host thread address is followed by the corresponding result.
- Tap Module sharing among threads (Singleton pattern). The console prints executeTaskPool success.
- Tap Shared immutable data among threads. The console prints executeTaskPool success.
Required Permissions
N/A
Dependencies
N/A
Constraints
- This sample is only supported on Huawei phones running standard systems.
- The HarmonyOS version must be HarmonyOS 5.0.5 Release or later.
- The DevEco Studio version must be DevEco Studio 5.0.5 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 5.0.5 Release SDK or later.