ArkTs 多worker 实例,并进行掉用传递消息,利用registerGlobalCallObject 传递对象及调用函数,获取buff。

实现多worer,并进行掉用传递消息,利用registerGlobalCallObject 传递对象及调用函数,获取buff。

注意:callGlobalCallObjectMethod 的方法在主线程中运行的。


HarmonyOS
2024-05-23 22:53:39
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
chjie1

使用的核心API

worker registerGlobalCallObject callGlobalCallObjectMethod SharedArrayBuffer

核心代码解释

1、pages/index.ets 入口,调用自定义函数

import { testMultyWorker } from './testWorker'   // 导入方法 
  
testMultyWorker();   // 测试多worker

2、pages/testWorker.ets 文件实现worker管理调度

import hilog from '@ohos.hilog'; 
import worker,{ MessageEvents } from '@ohos.worker'; 
  
const mainThreadTag:string ='mainthread==='; 
  
// 初始化2个worker,如果close或者terminate就不能用了 
let worker1:worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/worker1.ets', { name: "worker1" }); 
let worker2:worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/worker2.ets', { name: "worker2" }); 
  
// 自定义单例 
class TestObj { 
  private message : string = "this is a message from TestObj" 
  public getMessage() : string { 
    hilog.info(0, mainThreadTag, 'worker call obj func: getMessage()' ); 
    return this.message; 
  } 
  public getMessageWithInput(str : string) : string { 
    return this.message + " with input: " + str; 
  } 
  
  public setSharedArrayBuffer() { 
    let num = new Int16Array(this.sharedBuffer); 
    num[0] = 20; 
  } 
  
  public getSharedArrayBuffer():SharedArrayBuffer { 
    return this.sharedBuffer; 
  } 
  
  static registerObj:TestObj = new TestObj(); 
  private sharedBuffer: SharedArrayBuffer = new SharedArrayBuffer(1024); 
} 
  
// worker 的otnMessage 监听 
function onMessage(e:MessageEvents):void { 
  switch (e.data.type as number) { 
    case 0: 
      hilog.info(0, mainThreadTag, 'received message type: 0, value is: %{public}s, next to post msg to work2', e.data.value); 
      worker2.postMessage("This is msg from mainthread switch"); 
      break; 
    case 1: 
      hilog.info(0, mainThreadTag, 'received message value %{public}d, next to post msg to worker1', e.data.value as number); 
      worker1.postMessage({'type':0}); 
      break; 
    default: 
      hilog.info(0, mainThreadTag, 'invalid type, next to return'); 
      // 增加一个定时,体现worker运行 
      setTimeout(()=>{ hilog.info(0, mainThreadTag, 'invalid type, next to return22'); }, 5000); 
      break; 
  } 
} 
  
// export 函数 
export function testMultyWorker() { 
  TestObj.registerObj.setSharedArrayBuffer(); 
  // 在ThreadWorker实例上注册registerObj 
  worker2.registerGlobalCallObject("myObj", TestObj.registerObj); 
  worker1.registerGlobalCallObject("myObj", TestObj.registerObj); 
  
  hilog.info(0x0000, mainThreadTag, 'this is a msg to start worker'); 
  worker1.postMessage('this is a msg to start worker1'); 
  
  worker1.onmessage = onMessage; 
  worker2.onmessage = onMessage; 
  
  hilog.info(0, mainThreadTag, '=====end======'); 
  
  worker1.onexit = () => { 
    console.log("main thread terminate worker1"); 
  } 
  worker2.onexit = () => { 
    console.log("main thread terminate worker2"); 
  } 
} 
  

3、pages/worker1.ets 代码

import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker'; 
import hilog from '@ohos.hilog'; 
import process from '@ohos.process'; 
  
const worker1:string = 'worker1==='; 
  
const workerPort: ThreadWorkerGlobalScope = worker.workerPort; 
  
/** 
 * Defines the event handler to be called when the worker thread receives a message sent by the host thread. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e message data 
 */ 
workerPort.onmessage = (e: MessageEvents) => { 
  hilog.info(0, worker1, " === enter worker1, process uid:%{public}d, pid:%{public}d, tid:%{public}d ", 
    process.uid, process.pid, process.tid); 
  
  if (e.data.type == 0) { 
    workerPort.postMessage({ 'type': 2 }); 
    hilog.info(0, worker1, " === begin to end worker1 "); 
    // workerPort.close()    // close后不允许再使用,否则引发crash 
    return; 
  } 
  
  try { 
    let str1: string = workerPort.callGlobalCallObjectMethod("myObj", "getMessage", 0) as string; 
    hilog.info(0, worker1, " call shared class to get func: getMessage(), return is: %{public}s ", str1); 
  } catch (e) { 
    hilog.info(0, worker1, " call shared class getMessage get this %{public}s ,errcode %{public}d", e.message, e.code); 
  } 
  
  try { 
    let res: SharedArrayBuffer = workerPort.callGlobalCallObjectMethod("myObj", "getSharedArrayBuffer", 0) as SharedArrayBuffer; 
    let typedArr = new Int16Array(res); 
    hilog.info(0, worker1, " ===call shared class func: getSharedArrayBuffer(), return is: %{public}d ", typedArr[0]); 
    typedArr[0] = 25; 
    hilog.info(0, worker1, " ===work1 change the value to: %{public}d ", typedArr[0]); 
  } catch (e) { 
    hilog.info(0, worker1, " ===call shared class getSharedArrayBuffer get this %{public}s ", e.message); 
  } 
  
  workerPort.postMessage({ 'type': 0, 'value': 'this is a msg from worker1 to main' }); 
} 
  
/** 
 * Defines the event handler to be called when the worker receives a message that cannot be deserialized. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e message data 
 */ 
workerPort.onmessageerror = (e: MessageEvents) => { 
  hilog.info(0, worker1," received a message error"); 
} 
  
/** 
 * Defines the event handler to be called when an exception occurs during worker execution. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e error message 
 */ 
workerPort.onerror = (e: ErrorEvent) => { 
  hilog.info(0,worker1," worker1 error"); 
} 

4、pages/worker2.ets 代码

import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker'; 
import hilog from '@ohos.hilog'; 
import process from '@ohos.process'; 
  
const worker2:string = 'worker2==='; 
const workerPort: ThreadWorkerGlobalScope = worker.workerPort; 
  
/** 
 * Defines the event handler to be called when the worker thread receives a message sent by the host thread. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e message data 
 */ 
workerPort.onmessage = (e: MessageEvents) => { 
  hilog.info(0, worker2, " === enter worker2, process upt %{public}d,%{public}d,%{public}d ", 
    process.uid, process.pid, process.tid); 
  
  let str : string = workerPort.callGlobalCallObjectMethod("myObj", "getMessage", 0) as string; 
  hilog.info(0, worker2," call shared class func get value: %{public}s ", str); 
  
  let res : SharedArrayBuffer = workerPort.callGlobalCallObjectMethod("myObj", "getSharedArrayBuffer", 0) as SharedArrayBuffer; 
  
  let typedArr = new Int16Array(res); 
  
  hilog.info(0, worker2," ===call shared class func get value: %{public}d ", typedArr[0]); 
  
  workerPort.postMessage({'type' :1, 'value': typedArr[0] }); 
} 
  
/** 
 * Defines the event handler to be called when the worker receives a message that cannot be deserialized. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e message data 
 */ 
workerPort.onmessageerror = (e: MessageEvents) => { 
  hilog.info(0, worker2," received a message error"); 
} 
  
/** 
 * Defines the event handler to be called when an exception occurs during worker execution. 
 * The event handler is executed in the worker thread. 
 * 
 * @param e error message 
 */ 
workerPort.onerror = (e: ErrorEvent) => { 
  hilog.info(0, worker2," worker2 error"); 
}

实现效果

连续多次调用testMultyWorker() 的运行日志

01-24 15:16:30.959   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:30.959   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:30.962   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:30.962   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:30.963   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:30.963   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:30.963   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:30.964   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:30.964   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:30.964   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:30.964   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:30.965   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:30.965   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:30.966   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:30.966   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:30.966   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:31.653   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:31.654   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:31.654   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:31.656   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:31.656   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:31.656   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:31.657   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:31.657   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:31.657   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:31.657   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:31.658   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:31.658   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:31.658   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:31.659   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:31.659   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:31.659   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:31.812   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:32.033   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:32.033   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:32.034   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.034   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.034   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:32.035   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:32.035   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:32.035   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:32.035   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:32.036   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.036   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:32.036   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:32.037   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:32.038   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.038   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:32.038   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:32.376   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:32.376   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:32.377   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.377   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.378   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:32.378   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:32.378   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:32.378   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:32.379   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:32.379   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.379   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:32.379   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:32.380   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:32.380   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.380   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:32.380   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:32.777   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:32.778   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:32.779   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.779   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.779   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:32.780   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:32.780   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:32.780   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:32.781   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:32.781   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:32.781   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:32.782   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:32.782   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:32.783   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:32.783   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:32.783   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:33.161   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:33.161   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:33.162   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.163   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.163   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:33.163   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:33.163   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:33.164   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:33.164   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:33.164   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.164   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:33.165   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:33.165   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:33.165   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.165   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:33.166   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:33.520   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:33.521   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:33.521   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.522   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.522   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:33.522   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:33.522   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:33.523   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:33.523   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:33.523   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.523   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:33.524   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:33.524   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:33.524   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.525   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:33.525   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:33.889   10333-10333  A00000/mainthread===           com.examp...i11_test  I     this is a msg to start worker 
01-24 15:16:33.889   10333-10333  A00000/mainthread===           com.examp...i11_test  I     =====end====== 
01-24 15:16:33.890   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.891   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.891   10333-10371  A00000/worker1===              com.examp...i11_test  I      call shared class to get func: getMessage(), return is: this is a message from TestObj 
01-24 15:16:33.891   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===call shared class func: getSharedArrayBuffer(), return is: 20 
01-24 15:16:33.891   10333-10371  A00000/worker1===              com.examp...i11_test  I      ===work1 change the value to: 25 
01-24 15:16:33.892   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message type: 0, value is: this is a msg from worker1 to main, next to post msg to work2 
01-24 15:16:33.892   10333-10372  A00000/worker2===              com.examp...i11_test  I      === enter worker2, process upt 20020127,10333,10372 
01-24 15:16:33.892   10333-10333  A00000/mainthread===           com.examp...i11_test  I     worker call obj func: getMessage() 
01-24 15:16:33.893   10333-10372  A00000/worker2===              com.examp...i11_test  I      call shared class func get value: this is a message from TestObj 
01-24 15:16:33.893   10333-10372  A00000/worker2===              com.examp...i11_test  I      ===call shared class func get value: 25 
01-24 15:16:33.893   10333-10333  A00000/mainthread===           com.examp...i11_test  I     received message value 25, next to post msg to worker1 
01-24 15:16:33.894   10333-10371  A00000/worker1===              com.examp...i11_test  I      === enter worker1, process uid:20020127, pid:10333, tid:10371 
01-24 15:16:33.894   10333-10371  A00000/worker1===              com.examp...i11_test  I      === begin to end worker1 
01-24 15:16:33.894   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return 
01-24 15:16:35.968   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:36.660   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:37.039   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:37.382   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:37.784   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:38.166   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:38.525   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
01-24 15:16:38.895   10333-10333  A00000/mainthread===           com.examp...i11_test  I     invalid type, next to return22 
 

注明适配的版本信息

IDE版本:4.1.3.500

SDK版本:OpenHarmony 4..5.6

分享
微博
QQ
微信
回复
2024-05-24 22:27:18
相关问题
hap调用数据传递,有人知道吗?
534浏览 • 1回复 待解决
弹窗组件调用父组件函数传递
434浏览 • 1回复 待解决
ArkTs怎么传递对象或者类给Native
1035浏览 • 1回复 待解决
Router传递Object对象解读
762浏览 • 1回复 待解决
如何实现ArkTS与C/C++的对象传递
28浏览 • 1回复 待解决
本地service与本地应用间如何传递消息
4531浏览 • 1回复 待解决
TS侧如何批量传递函数到native侧
419浏览 • 1回复 待解决
如何获取router.back传递的参数
1293浏览 • 1回复 待解决
Native调用ArkTS侧类函数
394浏览 • 1回复 待解决
C++ 如何获取操作 Arkts 实例
435浏览 • 1回复 待解决
通过web上传图片并进行预览
454浏览 • 1回复 待解决