读书人

第五十四道Java小疑点

发布时间: 2012-12-18 12:43:41 作者: rapoo

第五十四道Java小问题

import java.util.concurrent.TimeUnit;class TestWork { volatile int i = 0; void f() throws InterruptedException {  while (i == 0) {   synchronized (this) {    wait();   }  }  System.out.println("Waken!"); } void g() {  synchronized (this) {   i = 1;   notifyAll();  } }}class Test { public static void main(String[] args) throws Exception {  final TestWork work = new TestWork();  new Thread() {   public void run() {    try {     work.f();    } catch (InterruptedException e) {    }   }  }.start();  TimeUnit.SECONDS.sleep(1);  new Thread() {   public void run() {    work.g();   }  }.start(); }}

?

请问以上程序的输出是:

读书人网 >编程

热点推荐