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**Worker** does not support the setting of the message priority, but **TaskPool** does. 354 355## What is the multithreading model of the system? (API version 10) 356 357**TaskPool** APIs are provided to support multithreading development. Resident time-consuming tasks can use worker threads, with the maximum number limited to eight. 358 359It is recommended that the FFRT thread pool be used on the native side. There is no restriction on pthread. 360 361## Can context be transferred across threads? (API version 10) 362 363Yes. Context can be directly transferred as a parameter. 364 365**References** 366 367[Shared Objects](../arkts-utils/serialization-support-types.md) 368 369## How do I implement secure access to the same shared memory in multithreaded concurrency scenarios? (API version 10) 370 371You 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. 372 373**Sample Code** 374 375```ts 376// index.ets 377let sab = new SharedArrayBuffer(32); 378// int32 buffer view for sab 379let i32a = new Int32Array(sab); 380i32a[0] = 0; 381 382let producer = new worker.ThreadWorker("entry/ets/workers/worker_producer.ts"); 383producer.postMessage(sab); 384 385function consumection(e: MessageEvents) { 386 let sab: SharedArrayBuffer = e.data; 387 let i32a = new Int32Array(sab); 388 console.info("Customer: received sab"); 389 while (true) { 390 Atomics.wait(i32a, 0, 0); //blocked here until be waked. 391 let length = i32a.length; 392 for (let i = length - 1; i > 0; i--) { 393 console.info("arraybuffer " + i + " value is " + i32a[i]); 394 i32a[i] = i; 395 } 396 } 397} 398``` 399 400## Which has a higher priority, the main thread or subthread? What are their task execution policies? (API version 10) 401 402As 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. 403 404Subthreads support priority setting, and the priority affects their scheduling. 405 406## Are there ArkTS APIs for forcibly switching thread execution and scheduling globally? (API version 10) 407 408**Worker** can throw tasks to the parent thread through **PostMessage**. **TaskPool** can send messages to the parent thread to trigger tasks. 409 410**References** 411 4121. [@ohos.taskpool (Using the Task Pool)](../reference/apis-arkts/js-apis-taskpool.md) 4132. [@ohos.worker (Worker Startup)](../reference/apis-arkts/js-apis-worker.md) 414 415## Does ArkTS support multithreading development using the shared memory model? (API version 10) 416 417Multiple 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. 418 419**References** 420 421[Multithreaded Concurrency Overview (TaskPool and Worker)](../arkts-utils/multi-thread-concurrency-overview.md) 422 423## 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) 424 425The 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. 426 427A sendable object must meet the following specifications: 4281. The member property is of the sendable or basic type (string, number, or boolean, but not container class, which will be supported later). 4292. Member properties must be initialized explicitly. 4303. Member functions cannot use closures. Only input parameters, **this** member, or variables imported through **import** can be used. 4314. Only a sendable class can inherit from another sendable class. 4325. @Sendable can be used only in .ets files. 4336. Private properties must be defined using **private**, rather than the number sign (#). 4347. The file to export cannot contain non-sendable properties. 4358. Either of the following transfer modes is used: 436 Serialized transfer: Deep copy to other threads is supported. 437 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. 438 439**References** 440 441[Multithreaded Concurrency Overview (TaskPool and Worker)](../arkts-utils/multi-thread-concurrency-overview.md) 442 443## Do ArkTS APIs support overloading? How do I implement overloading in them? (API version 10) 444 445ArkTS 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. 446 447ArkTS does not support overloading of multiple function bodies. 448 449Example: 450 451```ts 452class User { 453 age: number 454 455 constructor(age: number) { 456 this.age = age 457 } 458} 459 460// Declaration 461function test(param: User): number; 462 463function test(param: number, flag: boolean): number; 464 465// Implementation 466function test(param: User | number, flag?: boolean) { 467 if (typeof param === 'number') { 468 return param + (flag ? 1 : 0) 469 } else { 470 return param.age 471 } 472} 473``` 474 475## 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) 476 477A device has a limited number of cores. Too many threads cause high scheduling overhead and memory overhead. 478 479The system provides the ArkTS task pool and FFRT task pool to support unified scheduling. 480 481The 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. 482 483In other operating systems, the large number of application threads is caused by the synchronization lock and synchronization I/O programming. 484 485In 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. 486 487## 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) 488 489Tasks in the task pool can trigger the **onReceiveData** callback of the main thread through **sendData**. 490Multiple threads can use SharedArrayBuffer to operate the memory block. 491 492## Are multithreading operations on the preferences and databases thread safe? (API version 10) 493 494They are thread safe. 495 496## 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) 497 498If 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. 499 500## How do I implement synchronous function calls? (API version 10) 501 502Currently, 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. 503 504## Will the main thread be blocked if await is used in the main thread of ArkTS? (API version 10) 505 506**Description** 507 508If the following code is executed in the main thread, will the main thread be blocked? 509 510`const response = await reqeust.buildCall().execute<string>();` 511 512**Answer** 513 514It 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. 515 516## 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) 517 518Direct calls are not supported yet. 519 520## 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) 521 522- 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. 523- For React Native, the JS source code is run on the V8 engine provided by the system. 524 525## What data type conversion methods are used in ArkTS? Are they consistent with TS? (API version 10) 526 527ArkTS 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. 528 529ArkTS also supports built-in type conversion functions, such as **Number()**, **String()**, and **Boolean()**. 530 531**References** 532 533[TypeScript to ArkTS Cookbook](../quick-start/typescript-to-arkts-migration-guide.md) 534 535## Can an application manage the background I/O task pool? Is any open API provided for management? (API version 10) 536 537- 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. 538- The I/O task pool is scheduled at the bottom layer and cannot be managed by an application. 539 540## Will the system continue to support .ts file development in the future? (API version 10) 541 542**Description** 543 544Will 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. 545 546**Answer** 547 548The system will continue to support the standard TS syntax and be compatible with the existing third-party libraries implemented on TS. 549 550## Is dynamic module loading supported? How do I implement it? (API version 10) 551 552Currently, 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()**. 553 554The following is an example. The HAP dynamically imports **harlibrary** and calls the static member function **staticAdd()**, instance member function **instanceAdd()**, and global method **addHarLibrary()**. 555 556```ts 557/ / src/main/ets/utils/Calc.ets of harlibrary 558export class Calc { 559 public constructor() {} 560 public static staticAdd(a: number, b: number): number { 561 let c = a + b; 562 console.log("DynamicImport I'm harLibrary in staticAdd, %d + %d = %d", a, b, c); 563 return c; 564 } 565 public instanceAdd(a: number, b: number): number { 566 let c = a + b; 567 console.log("DynamicImport I'm harLibrary in instanseAdd, %d + %d = %d", a, b, c); 568 return c; 569 } 570} 571 572export function addHarLibrary(a: number, b: number): number { 573 let c = a + b; 574 console.log("DynamicImport I'm harLibrary in addHarLibrary, %d + %d = %d", a, b, c); 575 return c; 576} 577 578// index.ets of harlibrary 579export { Calc, addHarLibrary } from './src/main/ets/utils/Calc'; 580 581// index.ets of hap 582let harLibrary = 'harlibrary'; 583import(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. 584 ns.Calc.staticAdd(7, 8); // Call the static member function staticAdd() with reflection. 585 let calc: ESObject = new ns.Calc(); // Instantiate the class Calc. 586 calc.instanceAdd(8, 9); // Call the instance member function instanceAdd(). 587 ns.addHarLibrary(6, 7); // Call the global method addHarLibrary(). 588}); 589``` 590 591## Can ArkTS be used to develop AST structs or interfaces? (API version 11) 592 593AST 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. 594 595## 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? 596 597The ArkTS worker thread creates an ArkTS engine instance, which occupies extra memory. 598 599In 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. 600 601To address the problem that a large number of threads are required, you are advised to: 602 6031. Convert multi-thread tasks into concurrent tasks and distribute them through the task pool. 6042. Execute I/O tasks in the calling thread (which can be the TaskPool thread), rather than starting new threads for them. 6053. Use worker threads (no more than 8) for resident CPU intensive tasks (which is of a small number). 606 607**References** 608 609[Comparison Between TaskPool and Worker](../arkts-utils/taskpool-vs-worker.md) 610 611## What should I do if an error message related to modular loading is displayed when running an ArkTS application? 612 613The following errors related to modular loading may be displayed: 614 6151. "Cannot find dynamic-import module 'xxxx'" 616 617 This error indicates that the module to load is not compiled into the application package. 618 619 Possible cause: An expression is dynamically loaded as an input parameter, but the module path is incorrect. 620 621 ``` typescript 622 import(module).then(m=>{m.foo();}).catch(e=>{console.log(e)}) 623 ``` 624 625 Locating method: Print the path information of the module, and check whether the path is correct. 626 6272. "Cannot find module 'xxxx', which is application Entry Point" 628 629 This error indicates that the entry file is not found during application startup. 630 631 Possible cause: The entry file is not found during application startup. 632 633 Locating method: 634 635 (1) Open the application project-level build file **module.json5** in the **entry/src/main** directory. 636 637 638 The following is an example of some parameters in **module.json5**. 639 640 ``` 641 { 642 "module": { 643 "name": "entry", 644 "type": "entry", 645 ... 646 "abilities": [ 647 { 648 "name": "EntryAbility", // Module name. 649 "srcEntry": "./ets/entryability/EntryAbility.ts", // Relative path of the src directory to the project root directory. 650 "description": "$string:EntryAbility_desc", 651 "icon": "$media:icon", 652 "label": "$string:EntryAbility_label", 653 "startWindowIcon": "$media:icon", 654 "startWindowBackground": "$color:start_window_background", 655 "exported": true, 656 "skills": [ 657 { 658 "entities": [ 659 "entity.system.home" 660 ], 661 "actions": [ 662 "action.system.home" 663 ] 664 } 665 ] 666 } 667 ] 668 } 669 } 670 ``` 671 672 (2) Check the value of **srcEntry** under **"abilities** in **module.json5**. This parameter specifies the path of the entry file. 673 6743. "No export named 'xxxx' which exported by 'xxxx'" 675 676 This error indicates that no specific object is found in the module when the .so file in the HAP or HAR of the application is being loaded. 677 678 Possible cause: The dependency between modules is pre-parsed in the static compilation phase of the module. If the imported variable name in the .ets file is incorrect, an error message is displayed in both DevEco Studio and application build phase. Note that the dependency of C++ modules is checked at runtime. 679 680 Locating method: 681 682 Check whether the .so file in the application contains the exported variable that causes the error, and compare the exported variable with the imported variable in the .so file. If they are inconsistent, modify the variable. 683 684## Can long-time listening interfaces, such as **emitter.on**, be used in a TaskPool thread? 685 686Not recommended. 687 688**Principle Clarification** 689 6901. Long-time listening may adversely affect thread recycling or reuse. 6912. If a thread is reclaimed, the thread callback becomes invalid or an unexpected error occurs. 6923. 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. 693 694**Solution** 695 696You are advised to use a [continuous task](../reference/apis-arkts/js-apis-taskpool.md#longtask12). 697 698## Should I call onEnqueued, onStartExecution, onExecutionFailed, and onExecutionSucceeded in a certain sequence to listen for a task in the task pool? (API version 12) 699 700 The four APIs are independent and can be called in any sequence. 701 702## How do I use a sendable class in HAR? 703 704 Use the TS HAR. 705 706**References** 707 708[Compiling and Generating TS Files](../quick-start/har-package.md#compiling-and-generating-ts-files) 709 710## 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? 711 712When there is a dependency on the TS HAR, a UI component in the TS HAR cannot be referenced. 713 714To use a UI component in the HAR, use the source code HAR or JS HAR. 715 716**References** 717 718[HAR](../quick-start/har-package.md) 719 720## What are the commands used for setting various hdc properties? 721 722- To use the default properties, run the following command: **hdc shell param set persist.ark.properties 0x105c** 723- To disable multithreading detection and print abnormal stack frames, run the following command: **hdc shell param set persist.ark.properties -1** 724- To print the GC status, run the following command: **hdc shell param set persist.ark.properties 0x105e** 725- To enable multithreading detection, run the following command: **hdc shell param set persist.ark.properties 0x107c** 726- To enable multithreading detection and print abnormal stacks, run the following command: **hdc shell param set persist.ark.properties 0x127c** 727- To enable memory leak check for global objects, run the following command: **hdc shell param set persist.ark.properties 0x145c** 728- To enable memory leak check for global original values, run the following command: **hdc shell param set persist.ark.properties 0x185C** 729- To open the GC heap information, run the following command: **hdc shell param set persist.ark.properties 0x905c** 730- To enable microtask tracing (including enqueuing and execution), run the following command: **hdc shell param set persist.ark.properties 0x8105c** 731- 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** 732- 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** 733- 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** 734- To enable modular tracing, run the following command: **hdc shell param set persist.ark.properties 100105C** 735- To enable module-specific logging, run the following command: **hdc shell param set persist.ark.properties 200105C** 736### What are the commands used for performance data collection of CPU Profiler? 737- To collect data of the main thread in the cold start phase, run the following command: **hdc shell param set persist.ark.properties 0x705c** 738- To collect data of the worker thread in the cold start phase, run the following command: **hdc shell param set persist.ark.properties 0x1505c** 739- 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** 740- To collect data of the main thread in any phase, run the following command: **hdc shell param set persist.ark.properties 0x2505c** 741- To collect data of the worker thread in any phase, run the following command: **hdc shell param set persist.ark.properties 0x4505c** 742- 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** 743 744 <!--no_check-->