[size=large] 代码不是太长,就是下面这段代码,首先看一下,凭感觉回答有没有问题,然后运行一下。
public class Test {
public synchronized void t(){
new Thread(new Fuzhu()).start();
}
public static void main(String[] args) {
new Test().t();
}
}
class Fuzhu implements Runnable{
public void run() {
try {
this.wait(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行之后,有谁能回答一下,为什么回报 [color=red] java.lang.IllegalMonitorStateException: current thread not owner[/color] 这个异常.[/size]
public class Test {
public synchronized void t(){
new Thread(new Fuzhu()).start();
}
public static void main(String[] args) {
new Test().t();
}
}
class Fuzhu implements Runnable{
public void run() {
try {
this.wait(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行之后,有谁能回答一下,为什么回报 [color=red] java.lang.IllegalMonitorStateException: current thread not owner[/color] 这个异常.[/size]