public class ttt
{ public static void main(String args[])
{
account a=new account();
person person1=new person();
person person2=new person();
person1.cunkuanjine=1000;
person2.cunkuanjine=2000;
person1.zhanghu=a;
person2.zhanghu=a;
Thread a1=new Thread(person1);
Thread a2=new Thread(person2);
a1.start();
a2.start();
System.out.println(a.getnum());
if(a1.isAlive()==false&&a2.isAlive()==false){
System.out.println("结束");
}
}
}
class account
{
private int mum=0;
public void setnum(int mum)
{
this.mum=mum+this.mum;
}
public int getnum()
{
return this.mum;
}
}
class person implements Runnable
{ public static Object obj=new Object();
private String name;
public int cunkuanjine;
public account zhanghu;
public void run()
{
synchronized(obj){
cunqian(cunkuanjine,zhanghu);
System.out.println(zhanghu.getnum());
}
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public void cunqian(int a,account b)
{
b.setnum(a);
}
}
初学者自己的代码是这样的 按照我想的输出结果应该是 3000 1000 3000 结束 但是为啥运行输出 0 1000 3000