62,615
社区成员
发帖
与我相关
我的任务
分享
class A implements Runnable {
private int[] arr = new int[3];
Object sycroniz;
public synchronized void run() {
arr[0] = 4;
arr[1] = 5;
arr[2] = 6;
notify();
}
public synchronized int[] getArr() throws Exception {
wait();
return arr;
}
public void setArr(int[] arr) {
this.arr = arr;
}
}
public class Main {
public static void main(String args[]) throws Exception {
A a = new A();
int[] arr = {0, 3, 8};
a.setArr(arr);
Thread t = new Thread(a);
t.start();
int[] b = a.getArr();
for (int i = 0; i < b.length; i++) {
System.out.println(b[i]);
}
}
}