1# Common Object 2 3When a common object is transferred across threads, the object content of the two threads is the same, but the object points to the isolated memory area of each thread. For example, objects such as Object, Array, and Map defined in the Ecmascript262 specification implement cross-concurrent instance communication in this manner. The following figure shows the communication process. 4 5 6 7 8## Samples 9 10A simple example of transferring a common object is provided here. The implementation is as follows: 11 12```ts 13// Test.ets 14// Customize class TestA. 15export class TestA { 16 constructor(name: string) { 17 this.name = name; 18 } 19 name: string = 'ClassA'; 20} 21``` 22 23```ts 24// Index.ets 25import { taskpool } from '@kit.ArkTS'; 26import { BusinessError } from '@kit.BasicServicesKit'; 27import { TestA } from './Test'; 28 29@Concurrent 30async function test1(arg: TestA) { 31 console.info("TestA name is: " + arg.name); 32} 33 34@Entry 35@Component 36struct Index { 37 @State message: string = 'Hello World'; 38 39 build() { 40 RelativeContainer() { 41 Text(this.message) 42 .id('HelloWorld') 43 .fontSize(50) 44 .fontWeight(FontWeight.Bold) 45 .alignRules({ 46 center: { anchor: '__container__', align: VerticalAlign.Center }, 47 middle: { anchor: '__container__', align: HorizontalAlign.Center } 48 }) 49 .onClick(() => { 50 // 1. Create a test instance objA. 51 let objA = new TestA("TestA"); 52 // 2. Create a task and transfer objA to the task. objA is not a sendable object and is transferred to the subthread through serialization. 53 let task = new taskpool.Task(test1, objA); 54 3. Execute the task. 55 taskpool.execute(task).then(() => { 56 console.info("taskpool: execute task success!"); 57 }).catch((e:BusinessError) => { 58 console.error(`taskpool: execute task: Code: ${e.code}, message: ${e.message}`); 59 }) 60 }) 61 } 62 .height('100%') 63 .width('100%') 64 } 65} 66``` 67