class A implements Runnable
{
B a=new B();
Thread zhangsan=new Thread(this);
Thread lisi=new Thread(this);
Thread wangwu=new Thread(this);
zhangsan.start();
lisi.start();
wangwu.start();
public void run()
{
if(currentThread()==zhangsan)
{
a.course(20);
}
if(currentThread()==lisi)
{
a.course(10);
}
if(currentThread()==wangwu)
{
a.course(5);
}
}
}
class B
{
int money5=3,money10=0,money20=0;
public void course(int money)
{
if(money==5)
{
money5=money5+1;
System.out.println("你给的钱刚好");
}
if(money==10)
{
while(money5<1)
{
try
{
wait();
}
catch(InterruptedException e){
}
money5=money5-1;
money10=money10+1;
System.out.println("你给我10元,我找你5元");
}
}
if(money=20)
{
while(money5<3)
{
try
{
wait();
}
catch(InterruptedException e){
}
money5=money5-3;
money20=money20+1;
System.out.println("你给我20元,我找你15元");
}
}
notifyAll();
}
}
--------------------Configuration: <Default>--------------------
F:\java\syjc\ThreadTest.java:312: 需要 <标识符>
zhangsan.start();
^
F:\java\syjc\ThreadTest.java:313: 需要 <标识符>
lisi.start();
^
F:\java\syjc\ThreadTest.java:314: 需要 <标识符>
wangwu.start();
^
3 错误
Process completed.
但是不知道是什么错?谢谢指点