输出Exception in thread "Thread-1" java.lang.IllegalMonitorStateException at java.lang.Object.notify(Native Method)
at DataOut.run(InOutDemo.java:69)
at java.lang.Thread.run(Unknown Source)
Linda的年龄是10
作者: 李贺晓 时间: 2012-10-18 23:13
class TestNo
{
public static void main(String[] args)
{
Person p=new Person();
new Thread(new InPut(p)).start();
new Thread(new OutPut(p)).start();
}
}
class Person
{
String name;
int age;
boolean flag=false;
}
class InPut implements Runnable
{
private Person p;
InPut(Person p)
{
this.p=p;
}
public void run()
{
int x=0;
while(true)
{
synchronized(p)
{
if(p.flag)