1# ArkTS Common Library Development
2
3
4## Is memory isolation available between TaskPool, Worker, and ArkTS engine instances?
5
6**TaskPool** and **Worker** implement concurrency based on the actor model, which features memory isolation. As such, memory isolation is implemented between **TaskPool**, **Worker**, and ArkTS engine instances.
7
8
9## When will a TaskPool thread be destroyed in the task pool lifecycle?
10
11You do not need to manually manage the lifecycle of a task pool. If no task is executed for a certain period of time or no listening task is executed on the **TaskPool** thread, the thread may be destroyed.
12
13
14## Does TaskPool have restrictions on the task duration?
15
16The maximum task duration is 3 minutes (excluding the time used for Promise or async/await asynchronous call).
17
18
19## Which is recommended for scenarios with a large number of preloading tasks?
20
21A maximum of eight worker threads can co-exist. As such, **TaskPool** is recommended in this case. For details about the implementation features and use cases of **TaskPool** and **Worker**, see [Comparison Between Worker and TaskPool](../arkts-utils/taskpool-vs-worker.md).
22
23
24## Which is recommended in concurrent scenarios where threads need to be reused?
25
26A worker cannot execute different tasks. As such, **TaskPool** is recommended in this case.
27
28## Can I dynamically load modules (HAR, HSP, and .so modules) in TaskPool? (API version 10)
29
30Yes. **TaskPool** provides the same dynamic loading capability as the main thread. However, after a **TaskPool** thread is loaded, it cannot be reused by the main thread due to modular thread isolation.
31
32## How do I implement multithreaded data sharing? (API version 10)
33
34ArkTS uses a single-thread model and features memory isolation. Therefore, most common objects use serialization mode to implement cross-thread sharing.
35
36An object can be shared by transferring an ArrayBuffer or using a SharedArrayBuffer.
37
38**References**
39
40[Multithreaded Concurrency Overview (TaskPool and Worker)](../arkts-utils/multi-thread-concurrency-overview.md)
41
42## Cross-thread communication of JS objects depends on serialization. Is there any performance problem? (API version 10)
43
44Cross-thread object communication depends on serialization and deserialization, and the time required is related to the data volume. Therefore, you need to control the data volume to be transmitted, or use an ArrayBuffer or SharedArrayBuffer for transfer or sharing.
45
46
47## Some applications have more than 200 threads. Neither TaskPool nor Worker supports so many threads. How do I design a concurrent scheme? (API version 10)
48
49The underlying thread model interconnects with libuv. Therefore, after an application process starts, multiple I/O threads are used for I/O operations. For a JS thread, its asynchronous I/O operations are executed in the I/O threads, and it can handle other operations simultaneously. As such, this does not cause blocking and waiting issues.
50
51In addition, ArkTS provides TaskPool concurrent APIs, which are similar to the thread pool of GCD. Tasks can be executed without thread lifecycle management.
52
53To address the problem that a large number of threads are required, you are advised to:
54
55- Convert multi-thread tasks into concurrent tasks and distribute them through the task pool.
56- Execute I/O tasks in the calling thread (which can be the **TaskPool** thread), rather than starting new threads for them.
57- Use worker threads (no more than 8) for resident CPU intensive tasks (which is of a small number).
58
59**References**
60
61[Comparison Between TaskPool and Worker](../arkts-utils/taskpool-vs-worker.md)
62
63## How do I set task priorities, what are the differences between scheduling policies for these priorities, and what are the recommended scenarios for them? (API version 10)
64
65You can set different priorities for different tasks. The sequence of repeatedly executing the same task is irrelevant to the priority.
66
67**Sample Code**
68
69```ts
70@Concurrent
71function printArgs(args: number): number {
72  let t: number = Date.now();
73  while (Date.now() - t < 1000) { // 1000: delay 1s
74    continue;
75  }
76  console.info("printArgs: " + args);
77  return args;
78}
79
80let allCount = 100; // 100: test number
81let taskArray: Array<taskpool.Task> = [];
82// Create 300 tasks and add them to taskArray.
83for (let i: number = 1; i < allCount; i++) {
84  let task1: taskpool.Task = new taskpool.Task(printArgs, i);
85  taskArray.push(task1);
86  let task2: taskpool.Task = new taskpool.Task(printArgs, i * 10); // 10: test number
87  taskArray.push(task2);
88  let task3: taskpool.Task = new taskpool.Task(printArgs, i * 100); // 100: test number
89  taskArray.push(task3);
90}
91
92// Obtain different tasks from taskArray and specify different priorities for execution.
93for (let i: number = 0; i < allCount; i+=3) { // 3: Three tasks are executed each time. When obtaining tasks cyclically, obtain the three items following the last batch to ensure that different tasks are obtained each time.
94  taskpool.execute(taskArray[i], taskpool.Priority.HIGH);
95  taskpool.execute(taskArray[i + 1], taskpool.Priority.LOW);
96  taskpool.execute(taskArray[i + 2], taskpool.Priority.MEDIUM);
97}
98```
99
100**References**
101
102[Priority](../reference/apis-arkts/js-apis-taskpool.md)
103
104## How do I convert the implementation of the memory-sharing thread model into the implementation of the ArkTS thread model (memory isolation)? (API version 11)
105
106Use **TaskPool** APIs for conversion in the following scenarios:
107
108Scenario 1: Execute independent time-consuming tasks in a subthread, rather than the main thread.
109
110Sample code for memory sharing
111
112```ts
113class Task {
114  static run(args) {
115    // Do some independent task
116  }
117}
118
119let thread = new Thread(() => {
120  let result = Task.run(args)
121  // deal with result
122})
123```
124
125ArkTS sample code
126
127```ts
128import taskpool from '@ohos.taskpool'
129@Concurrent
130function run(args: string) {
131  // Do some independent task
132}
133
134let args: string = '';
135let task = new taskpool.Task(run, args)
136taskpool.execute(task).then((ret: string) => {
137  // Return result
138})
139```
140
141Scenario 2: Use the created class instance in a subthread, rather than the main thread.
142
143Sample code for memory sharing
144
145```ts
146class Material {
147  action(args) {
148    // Do some independent task
149  }
150}
151
152let material = new Material()
153let thread = new Thread(() => {
154  let result = material.action(args)
155  // deal with result
156})
157```
158
159ArkTS sample code
160
161```ts
162import taskpool from '@ohos.taskpool'
163@Concurrent
164function runner(material: Material, args: string): void {
165  return material.action(args);
166}
167@Sendable
168class Material {
169  action(args: string) {
170    // Do some independent task
171  }
172}
173
174let material = new Material()
175taskpool.execute(runner, material).then((ret: string) => {
176  // Return result
177})
178```
179
180Scenario 3: Execute independent time-consuming tasks in a subthread, rather than the main thread.
181Sample code for memory sharing
182
183```ts
184class Task {
185  run(args) {
186    // Do some independent task
187    task.result = true
188  }
189}
190
191let task = new Task()
192let thread = new Thread(() => {
193  let result = task.run(args)
194  // deal with result
195})
196```
197
198ArkTS sample code
199
200```ts
201import taskpool from '@ohos.taskpool'
202@Concurrent
203function runner(task: Task) {
204  let args: string = '';
205  task.run(args);
206}
207@Sendable
208class Task {
209  result: string = '';
210
211  run(args: string) {
212    // Do some independent task
213    return true;
214  }
215}
216
217let task = new Task();
218taskpool.execute(runner, task).then((ret: string) => {
219  task.result = ret;
220})
221```
222
223Scenario 4: A subthread proactively updates the status of the main thread.
224Sample code for memory sharing
225
226```ts
227class Task {
228  run(args) {
229    // Do some independent task
230    runOnUiThread(() => {
231      UpdateUI(result)
232    })
233  }
234}
235
236let task = new Task()
237let thread = new Thread(() => {
238  let result = task.run(args)
239  // deal with result
240})
241```
242
243ArkTS sample code
244
245```ts
246import taskpool from '@ohos.taskpool'
247@Concurrent
248function runner(task) {
249  task.run()
250}
251
252@Sendable
253class Task {
254  run(args) {
255    // Do some independent task
256    taskpool.Task.sendData(result)
257  }
258}
259
260let task = new Task()
261let run = new taskpool.Task(runner, task)
262run.onReceiveData((result) => {
263  UpdateUI(result)
264})
265taskpool.execute(run).then((ret) => {
266  // Return result
267})
268```
269
270Scenario 5: A subthread synchronously calls the interface of the main thread.
271Sample code for memory sharing
272
273```ts
274class SdkU3d {
275  static getInst() {
276    return SdkMgr.getInst();
277  }
278
279  getPropStr(str: string) {
280    return xx;
281  }
282}
283
284let thread = new Thread(() => {
285  // Game thread
286  let sdk = SdkU3d.getInst()
287  let ret = sdk.getPropStr("xx")
288})
289```
290
291ArkTS sample code
292
293```ts
294// Main thread
295class SdkU3d {
296  static getInst() {
297    return SdkMgr.getInst();
298  }
299
300  getPropStr(str: string) {
301  }
302}
303
304const workerInstance = new
305worker.ThreadWorker("xx/worker.ts");
306let sdk = SdkU3d.getInst()
307workerInstance.registerGlobalCallObject("instance_xx", sdk);
308workerInstance.postMessage("start");
309const mainPort = worker.workerPort;
310mainPort.onmessage = (e: MessageEvents): void => {
311  let ret = mainPort.callGlobalCallObjectMethod("instance_xx", "getPropStr", "xx");
312}
313```
314**References**
315
316[Concurrency Overview](../arkts-utils/concurrency-overview.md)
317
318## What are the differences between TaskPool and Worker? What are their recommended scenarios? (API version 10)
319
320**TaskPool** and **Worker** are concurrent APIs of different granularities. **TaskPool** provides APIs at the level of tasks, whereas **Worker** provides APIs at the level of threads or services.
321
322**TaskPool** simplifies concurrent program development, supports priority setting and cancellation, and saves system resources and optimizes scheduling through unified management.
323
324Similarities: In terms of interaction with JS-related threads, both of them feature memory isolation. They pose the same restrictions on parameters and value ranges, and they also have overhead. (Pay attention to the granularity of concurrent tasks.)
325
326**References**
327
328[Comparison Between TaskPool and Worker](../arkts-utils/taskpool-vs-worker.md)
329
330## Do Worker and TaskPool limit the number of threads? What will happen if the maximum number is reached? Will the task pool be affected when the number of worker threads reaches the upper limit? (API version 10)
331
332**TaskPool** dynamically adjusts the number of threads based on hardware conditions and task loads. It does not support setting a number. Tasks are added to the thread pool, and high-priority tasks are executed first.
333
334A maximum of eight worker threads can be created. No more worker threads can be created when the maximum number is reached.
335
336**TaskPool** and **Worker** are independent of each other.
337
338**References**
339
340[Comparison Between TaskPool and Worker](../arkts-utils/taskpool-vs-worker.md)
341
342## Is there a thread-safe container class? (API version 10)
343
344Objects are not directly shared, and therefore all containers are thread-safe.
345
346**References**
347
348[Asynchronous Concurrency Overview (Promise and Async/Await)](../arkts-utils/async-concurrency-overview.md)
349
350## What is the task scheduling mechanism in TaskPool and Worker? Do they provide the same event loop mechanism as the JS single thread?  (API version 10)
351
352**TaskPool** and **Worker** use the event loop to receive messages exchanged between threads.
353
354**Worker** does not support the setting of the message priority, but **TaskPool** does.
355
356## What is the multithreading model of the system? (API version 10)
357
358**TaskPool** APIs are provided to support multithreading development. Resident time-consuming tasks can use worker threads, with the maximum number limited to eight.
359
360It is recommended that the FFRT thread pool be used on the native side. There is no restriction on pthread.
361
362## Can context be transferred across threads? (API version 10)
363
364Yes. Context can be directly transferred as a parameter.
365
366**References**
367
3681. [Sendable Object Overview](../arkts-utils/arkts-sendable.md)
369
370## How do I implement secure access to the same shared memory in multithreaded concurrency scenarios? (API version 10)
371
372You can use SharedArrayBuffer. If multiple operations are simultaneously performed to modify data stored in an object of the SharedArrayBuffer type, you must use atomic operations to ensure data synchronization. The atomic operations ensure that the current operation is complete before the next operation starts.
373
374**Sample Code**
375
376```ts
377// index.ets
378let sab = new SharedArrayBuffer(32);
379// int32 buffer view for sab
380let i32a = new Int32Array(sab);
381i32a[0] = 0;
382
383let producer = new worker.ThreadWorker("entry/ets/workers/worker_producer.ts");
384producer.postMessage(sab);
385
386function consumection(e: MessageEvents) {
387  let sab: SharedArrayBuffer = e.data;
388  let i32a = new Int32Array(sab);
389  console.info("Customer: received sab");
390  while (true) {
391    Atomics.wait(i32a, 0, 0); //blocked here until be waked.
392    let length = i32a.length;
393    for (let i = length - 1; i > 0; i--) {
394      console.info("arraybuffer " + i + " value is " + i32a[i]);
395      i32a[i] = i;
396    }
397  }
398}
399```
400
401## Which has a higher priority, the main thread or subthread? What are their task execution policies? (API version 10)
402
403As the UI thread, the main thread has the highest priority. When the load is high, a thread with a higher priority is executed faster. When the load is low, the execution pace is similar for threads with different priorities.
404
405Subthreads support priority setting, and the priority affects their scheduling.
406
407## Are there ArkTS APIs for forcibly switching thread execution and scheduling globally? (API version 10)
408
409**Worker** can throw tasks to the parent thread through **PostMessage**. **TaskPool** can send messages to the parent thread to trigger tasks.
410
411**References**
412
4131. [@ohos.taskpool (Using the Task Pool)](../reference/apis-arkts/js-apis-taskpool.md)
4142. [@ohos.worker (Worker Startup)](../reference/apis-arkts/js-apis-worker.md)
415
416## Does ArkTS support multithreading development using the shared memory model? (API version 10)
417
418Multiple threads cannot perform operations on the same memory object simultaneously by locking the memory object. ArkTS is an actor model that supports cross-thread memory isolation. Currently, only SharedArrayBuffer or native-layer objects can be shared.
419
420**References**
421
422[Multithreaded Concurrency Overview (TaskPool and Worker)](../arkts-utils/multi-thread-concurrency-overview.md)
423
424## What is the memory sharing principle of a sendable class object of ArkTS? What are the restrictions? How do I use it? (API version 11)
425
426The sendable class is an extension of the actor model. The memory of a sendable class object is shared among threads. However, lock-free must be used for a single thread. To prevent multiple threads from simultaneously accessing a sendable class object, use the synchronization mechanism to ensure thread safe.
427
428A sendable object must meet the following specifications:
4291. The member property is of the sendable or basic type (string, number, or boolean, but not container class, which will be supported later).
4302. Member properties must be initialized explicitly.
4313. Member functions cannot use closures. Only input parameters, **this** member, or variables imported through **import** can be used.
4324. Only a sendable class can inherit from another sendable class.
4335. @Sendable can be used only in .ets files.
4346. Private properties must be defined using **private**, rather than the number sign (#).
4357. The file to export cannot contain non-sendable properties.
4368. Either of the following transfer modes is used:
437    Serialized transfer: Deep copy to other threads is supported.
438    Sharing mode: Cross-thread reference transfer is supported. Multiple threads can read and write data at the same time. You need to use the synchronization mechanism to avoid multi-thread competition.
439
440**References**
441
442[Multithreaded Concurrency Overview (TaskPool and Worker)](../arkts-utils/multi-thread-concurrency-overview.md)
443
444## Do ArkTS APIs support overloading? How do I implement overloading in them? (API version 10)
445
446ArkTS supports overloading in TS, that is, multiple overload signatures + implementation signature + function bodies. Function signatures are used only for type check during build. They are not retained at runtime.
447
448ArkTS does not support overloading of multiple function bodies.
449
450Example:
451
452```ts
453class User {
454  age: number
455
456  constructor(age: number) {
457    this.age = age
458  }
459}
460
461// Declaration
462function test(param: User): number;
463
464function test(param: number, flag: boolean): number;
465
466// Implementation
467function test(param: User | number, flag?: boolean) {
468  if (typeof param === 'number') {
469    return param + (flag ? 1 : 0)
470  } else {
471    return param.age
472  }
473}
474```
475
476##  What is the thread mechanism? Is each thread a separate JS engine? If a thread has relatively low overhead, why is the number of threads limited? (API version 10)
477
478A device has a limited number of cores. Too many threads cause high scheduling overhead and memory overhead.
479
480The system provides the ArkTS task pool and FFRT task pool to support unified scheduling.
481
482The JS part of the ArkTS thread is implemented based on the actor model. Each thread has an independent JS environment instance. Therefore, starting a thread consumes a large amount of memory.
483
484In other operating systems, the large number of application threads is caused by the synchronization lock and synchronization I/O programming.
485
486In OpenHarmony, asynchronous I/O calls are distributed to the I/O thread pool and do not block application threads. Therefore, the number of threads required is far less than that in other operating systems.
487
488##  How does the task pool communicate with the main thread during task execution? How do I implement simultaneous access to the same memory variable? (API version 10)
489
490Tasks in the task pool can trigger the **onReceiveData** callback of the main thread through **sendData**.
491Multiple threads can use SharedArrayBuffer to operate the memory block.
492
493##  Are multithreading operations on the preferences and databases thread safe? (API version 10)
494
495They are thread safe.
496
497##  If most background tasks (computing, tracing, and storage) in ArkTS use asynchronous concurrency mode, will the main thread become slower and finally cause frame freezing and frame loss? (API version 10)
498
499If I/O operations are not involved, asynchronous tasks of ArkTS APIs are triggered at the microtask execution time of the main thread and still occupy the main thread. You are advised to use **TaskPool** to distribute the tasks to the background task pool.
500
501##  How do I implement synchronous function calls? (API version 10)
502
503Currently, the use of **synchronized** is not supported. In the future, the AsyncLock synchronization mechanism will be supported, where code blocks to be synchronized can be placed in asynchronous code blocks.
504
505##  Will the main thread be blocked if await is used in the main thread of ArkTS? (API version 10)
506
507**Description**
508
509If the following code is executed in the main thread, will the main thread be blocked?
510
511`const response = await reqeust.buildCall().execute<string>();`
512
513**Answer**
514
515It will not block the main thread. await suspends the current asynchronous task and wakes up the task until the conditions are met. The main thread can process other tasks.
516
517##  In C/C++ code, how do I directly call ArkTS APIs in the subthread instead of posting messages to the main thread? (API version 10)
518
519Direct calls are not supported yet.
520
521## Is the underlying running environment of ArkTS code self-developed or open-source? Is the same running environment used for React Native code? (API version 10)
522
523- On the in-house ArkCompiler, the bytecode is run. The bytecode is generated after the ArkTS, TS, or JS source code is compiled using the ArkCompiler toolchain.
524- For React Native, the JS source code is run on the V8 engine provided by the system.
525
526## What data type conversion methods are used in ArkTS? Are they consistent with TS? (API version 10)
527
528ArkTS supports as type conversion of TS, but not type conversion using the <> operator. Currently, the as type conversion can be used during build, but not at runtime.
529
530ArkTS also supports built-in type conversion functions, such as **Number()**, **String()**, and **Boolean()**.
531
532**References**
533
534[TypeScript to ArkTS Cookbook](../quick-start/typescript-to-arkts-migration-guide.md)
535
536## Can an application manage the background I/O task pool? Is any open API provided for management? (API version 10)
537
538- The background TaskPool threads are determined by the load and hardware. No open API is provided. However, you can use the serial queue and task group for task management.
539- The I/O task pool is scheduled at the bottom layer and cannot be managed by an application.
540
541## Will the system continue to support .ts file development in the future? (API version 10)
542
543**Description**
544
545Will the basic libraries implemented based on TS be compatible in the future? For example, the .ts file supports **any** and dynamic type conversion at runtime, but the .ets file does not.
546
547**Answer**
548
549The system will continue to support the standard TS syntax and be compatible with the existing third-party libraries implemented on TS.
550
551## Is dynamic module loading supported? How do I implement it? (API version 10)
552
553Currently, the binary package on the device side cannot be dynamically loaded. You can use the dynamic import feature for asynchronous loading. This achieves the effect similar to the reflection API **Class.forName()**.
554
555The following is an example. The HAP dynamically imports **harlibrary** and calls the static member function **staticAdd()**, instance member function **instanceAdd()**, and global method **addHarLibrary()**.
556
557```ts
558/ / src/main/ets/utils/Calc.ets of harlibrary
559export class Calc {
560  public constructor() {}
561  public static staticAdd(a: number, b: number): number {
562    let c = a + b;
563    console.log("DynamicImport I'm harLibrary in staticAdd, %d + %d = %d", a, b, c);
564    return c;
565  }
566  public instanceAdd(a: number, b: number): number {
567    let c = a + b;
568    console.log("DynamicImport I'm harLibrary in instanseAdd, %d + %d = %d", a, b, c);
569    return c;
570  }
571}
572
573export function addHarLibrary(a: number, b: number): number {
574  let c = a + b;
575  console.log("DynamicImport I'm harLibrary in addHarLibrary, %d + %d = %d", a, b, c);
576  return c;
577}
578
579// index.ets of harlibrary
580export { Calc, addHarLibrary } from './src/main/ets/utils/Calc';
581
582// index.ets of hap
583let harLibrary = 'harlibrary';
584import(harLibrary).then((ns: ESObject) => {  // Dynamic variable import is a new feature. Changing an input parameter to the string 'harlibrary' is supported in earlier versions. You can also use the await import mode.
585  ns.Calc.staticAdd(7, 8);  // Call the static member function staticAdd() with reflection.
586  let calc: ESObject = new ns.Calc();  // Instantiate the class Calc.
587  calc.instanceAdd(8, 9);  // Call the instance member function instanceAdd().
588  ns.addHarLibrary(6, 7);  // Call the global method addHarLibrary().
589});
590```
591
592## Can ArkTS be used to develop AST structs or interfaces? (API version 11)
593
594AST is an intermediate data structure during compilation. The data is unstable and may change as the language or compiler evolves. Therefore, there is no plan to open AST to developers.
595
596## Multithreading occupies a large amount of memory. Each thread requires an ArkTS engine, which means more memory is occupied. How do I fully utilize the device performance with a limited number of threads?
597
598The ArkTS worker thread creates an ArkTS engine instance, which occupies extra memory.
599
600In addition, ArkTS provides TaskPool concurrent APIs, which are similar to the thread pool of GCD. Tasks can be executed without thread lifecycle management. Tasks are scheduled to a limited number of worker threads for execution. Multiple tasks share these worker threads (ArkTS engine instances). The system scales in or out the number of worker threads based on the load to maximize the hard performance.
601
602To address the problem that a large number of threads are required, you are advised to:
603
6041. Convert multi-thread tasks into concurrent tasks and distribute them through the task pool.
6052. Execute I/O tasks in the calling thread (which can be the TaskPool thread), rather than starting new threads for them.
6063. Use worker threads (no more than 8) for resident CPU intensive tasks (which is of a small number).
607
608**References**
609
610[Comparison Between TaskPool and Worker](../arkts-utils/taskpool-vs-worker.md)
611
612## Can long-time listening interfaces, such as **emitter.on**, be used in a TaskPool thread?
613
614Not recommended.
615
616**Principle Clarification**
617
6181. Long-time listening may adversely affect thread recycling or reuse.
6192. If a thread is reclaimed, the thread callback becomes invalid or an unexpected error occurs.
6203. If a task function is executed for multiple times, listening may be generated in different threads. Consequently, the result may fail to meet your expectation.
621
622**Solution**
623
624You are advised to use a [continuous task](../reference/apis-arkts/js-apis-taskpool.md#longtask12).
625
626## Should I call onEnqueued, onStartExecution, onExecutionFailed, and onExecutionSucceeded in a certain sequence to listen for a task in the task pool? (API version 12)
627
628The four APIs are independent and can be called in any sequence.
629
630## How do I use a sendable class in HAR?
631
632Use the TS HAR.
633
634**References**
635
636[Building TS Files](../quick-start/har-package.md#building-ts-files)
637
638## When a UI component in the TS HAR is used, an error message is displayed during the build, indicating that the UI component does not meet UI component syntax. What should I do?
639
640When there is a dependency on the TS HAR, a UI component in the TS HAR cannot be referenced.
641
642To use a UI component in the HAR, use the source code HAR or JS HAR.
643
644**References**
645
646[HAR](../quick-start/har-package.md)
647
648## What are the commands used for setting various hdc properties?
649
650- To use the default properties, run the following command: **hdc shell param set persist.ark.properties 0x105c**
651- To disable multithreading detection and print abnormal stack frames, run the following command: **hdc shell param set persist.ark.properties -1**
652- To print the GC status, run the following command: **hdc shell param set persist.ark.properties 0x105e**
653- To enable multithreading detection, run the following command: **hdc shell param set persist.ark.properties 0x107c**
654- To enable multithreading detection and print abnormal stacks, run the following command: **hdc shell param set persist.ark.properties 0x127c**
655- To enable memory leak check for global objects, run the following command: **hdc shell param set persist.ark.properties 0x145c**
656- To enable memory leak check for global original values, run the following command: **hdc shell param set persist.ark.properties 0x185C**
657- To open the GC heap information, run the following command: **hdc shell param set persist.ark.properties 0x905c**
658- To enable microtask tracing (including enqueuing and execution), run the following command: **hdc shell param set persist.ark.properties 0x8105c**
659- To use ArkProperties to control whether to enable the socket debugger of an earlier version, run the following command: **hdc shell param set persist.ark.properties 0x10105C**
660- To use DISABLE to adapt to the existing ArkProperties in the test script, run the following command: **hdc shell param set persist.ark.properties 0x40105C**
661- To enhance error reporting during the loading of .so files to a module, run the following command: **hdc shell param set persist.ark.properties 0x80105C**
662- To enable modular tracing, run the following command: **hdc shell param set persist.ark.properties 100105C**
663- To enable module-specific logging, run the following command: **hdc shell param set persist.ark.properties 200105C**
664### What are the commands used for performance data collection of CPU Profiler?
665- To collect data of the main thread in the cold start phase, run the following command: **hdc shell param set persist.ark.properties 0x705c**
666- To collect data of the worker thread in the cold start phase, run the following command: **hdc shell param set persist.ark.properties 0x1505c**
667- To collect data of the main thread and worker thread in the cold start phase, run the following command: **hdc shell param set persist.ark.properties 0x1705c**
668- To collect data of the main thread in any phase, run the following command: **hdc shell param set persist.ark.properties 0x2505c**
669- To collect data of the worker thread in any phase, run the following command: **hdc shell param set persist.ark.properties 0x4505c**
670- To collect data of the main thread and worker thread in any phase, run the following command: **hdc shell param set persist.ark.properties 0x6505c**
671
672## Does ArkTS use an asynchronous I/O model similar to Node.js?
673
674Yes. Node.js uses the event loop system to process asynchronous operations, which are processed using callback functions or promises. Similarly, ArkTS uses a coroutine-based asynchronous I/O mechanism, in which I/O events are distributed to I/O threads, without blocking JS threads. Asynchronous operations can be processed using callback functions or Promise/async/await paradigm.
675
676## Do I/O intensive tasks like network requests need to be processed by multiple threads?
677
678The decision depends on the specific service scenario and implementation details. If the I/O operations are not frequent and do not affect other services of the UI main thread, multithreading is unnecessary. However, if there are many I/O requests and it takes a long time for the UI main thread to distribute these requests, employing multithreading can enhance the application's performance and response speed. The final decision depends on DevEco Studio Profiler.
679
680## Does the @ohos.net.http network framework need to use TaskPool for handling tasks?
681
682The decision depends on the specific service scenario and implementation details. If the number of network requests is small or the subsequent network data processing is not particularly time-consuming, then employing TaskPool to manage thread creation, recycling, and data transfer overhead is unnecessary. However, if there are a large number of network requests and it takes a long time to process the data obtained, leveraging TaskPool can help manage these tasks more efficiently and reduce the workload on the UI main thread.
683