732143c8Add on Mar 18History
FilesLast commitLast 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
README

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

  1. Tap Scenarios for concurrent execution of time-consuming tasks. The console prints Return:3.
  2. Tap Scenarios of concurrent execution of long-duration tasks. The console prints execute success.
  3. Tap Multi-tasking concurrent execution (serial sequential dependency). The console prints result is abc.
  4. 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.
  5. Tap Multi-task synchronous waiting for results (task group). The console prints res: followed by the corresponding result.
  6. Tap Multi-task priority scheduling. The console prints execColorInfo success.
  7. Tap Task Delay Scheduling. The console prints taskpool result: 100.
  8. Tap Cross-language multithreaded communication (C++ and ArkTS). The console prints click nativeCall success.
  9. Tap Inter-thread module sharing (Singleton pattern) (Solution 1). The console prints host thread address is followed by the corresponding result.
  10. Tap Module sharing among threads (Singleton pattern). The console prints executeTaskPool success.
  11. Tap Shared immutable data among threads. The console prints executeTaskPool success.

Required Permissions

N/A

Dependencies

N/A

Constraints

  1. This sample is only supported on Huawei phones running standard systems.
  2. The HarmonyOS version must be HarmonyOS 5.0.5 Release or later.
  3. The DevEco Studio version must be DevEco Studio 5.0.5 Release or later.
  4. The HarmonyOS SDK version must be HarmonyOS 5.0.5 Release SDK or later.