62,628
社区成员
发帖
与我相关
我的任务
分享
public class ThreadA {
public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadB b = new ThreadB();
b.start();
synchronized(b){
try {
System.out.println("this is a thread");
b.wait();
} catch(InterruptedException e) {
e.printStackTrace();
}
System.out.println("b.total="+b.total);
}
}
}
class ThreadB extends Thread {
int total;
public void run() {
synchronized (this) {
for(int i = 0;i < 10;i ++) {
total +=i;
System.out.println(i);
}
notify();
}
}
}