62,614
社区成员
发帖
与我相关
我的任务
分享
package t4;
public class test {
public static void main(String[] args) {
Integer i = 40;
t41 t1 = new t41(i);
t41 t2 = new t41(i);
t1.start();
t2.start();
}
}
package t4;
public class t41 extends Thread{
private Integer i;
public t41(Integer i){
this.i = i ;
}
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (i) {
System.out.println(i);
i--;
try {
Thread.sleep(1000);
i.notifyAll();
i.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
40
40
Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
at t4.t41.run(t41.java:17)
Exception in thread "Thread-1" java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
at t4.t41.run(t41.java:17)