yichenglong
当前经验9分,升级还需271分
下一等级:Lv.2如何升级?
-
Z金豆:
0
- 城 市:贵州
- 注 册:2012-10-20
- 登 录:2014-12-10
|
发表于 2012-10-22 20:18:01
楼主
|
为什么三个等待都被唤醒了,最后又程序文档class Demo6{ public static void main(String[] args) { Go1 q=new Go1(); Go2 qq=new Go2(q); Go3 qqq=new Go3(q); Come w=new Come(q); q.start(); qq.start(); qqq.start(); w.start(); }}class Go1 extends Thread{ public void run() { synchronized (this) { System.out.println("1"); try { wait(); } catch (Exception e) { } } System.out.println("一"); } }class Go2 extends Thread{ Go1 g; Go2(Go1 g) { this.g=g; } public void run() { synchronized (g) { System.out.println("2"); try { g.wait(); } catch (Exception e) { } } System.out.println("二"); }}class Go3 extends Thread{ Go1 g; Go3(Go1 g) { this.g=g; } public void run() { synchronized (g) { System.out.println("3"); try { g.wait(); } catch (Exception e) { } } System.out.println("三"); }}class Come extends Thread { Go1 r; Come(Go1 r) { this.r=r; } public void run() { try { sleep(100); } catch (Exception e) { } synchronized (r) { r.notify(); System.out.println("lock open"); } }}
|