class demo
{
public static void main(String[] args)
{
R r =new R();
la in=new la(r);
yun to=new yun(r);
Thread t1=new Thread(in);
Thread t2=new Thread(to);
t1.start();
t2.start();
}
}
class R
{
private String name;
private int gonghao=1;
private boolean biaoji;
public synchronized void lajin(String name)
{
while(biaoji)
{
try
{
this.wait();
}
catch(Exception e)
{
}
}
this.name=name+"...."+gonghao++;
System.out.println(Thread.currentThread().getName()+"...拉煤者..."+this.name);
biaoji=true;
this.notifyAll();
}
public synchronized void lachu()
{
while(!biaoji)
{
try
{
this.wait();
}
catch(Exception e)
{
}
}
System.out.println(Thread.currentThread().getName()+"...运走煤者..."+this.name);
biaoji=false;
this.notifyAll();
}
}
class la implements Runnable
{
private R r;
la(R r)
{
this.r=r;
}
public void run()
{
while (true)
{
R.lajin("煤");
}
}
}
class yun implements Runnable
{
private R r;
yun(R r)
{
this.r=r;
}
public void run()
{
while (true)
{
R.lachu();
}
}
}
---------------------------------------------------------------------------------------------下面是编译器报的错误,我感觉我代码没问题啊:Q
lamei01.java:72: 错误: 无法从静态上下文中引用非静态 方法 lajin(String)
R.lajin("煤");
^
lamei01.java:87: 错误: 无法从静态上下文中引用非静态 方法 lachu()
R.lachu();
|
|