请教一个关于Java抛出异常问题,在线等!!
迷失在太空 2007-08-08 05:47:22 运行如下程序抛出异常:
public class Agg {
public static void main(String argv[]) {
Agg a = new Agg();
a.go();
}
public void go() {
DSRoss ds1 = new DSRoss("one");
ds1.start();
}
}
class DSRoss extends Thread {
private String sTname = "";
DSRoss(String s) {
sTname = s;
}
public void run() {
notwait();
System.out.println("finished");
}
public void notwait() {
while (true) {
try {
System.out.println("waiting");
wait();
}
catch (InterruptedException ie) {
}
System.out.println(sTname);
notifyAll();
}
}
}
调试的时候提示wait()这里有错误:Object synchronization method was called from an unsynchronized block of code.
请问为什么这里错误,如何更改呢?