import java.text.NumberFormat;
publicclass Threadt {
publicstaticvoid main(String args[]){
counter totilet=new counter();
ba b1=new ba(totilet,"1");
ba b2=new ba(totilet,"2");
b1.start();
b2.start();
}}
class baextends Thread{
counter totilet;
inti;
String name;
ba(counter to,String name){
totilet=to;
this.name=name;
}
publicvoid run(){
while(i++<100){
totilet.run(name);
try{
Thread.sleep(1000);
}catch(Exception e){}
}
}}
class counter{
NumberFormat formatter=NumberFormat.getCurrencyInstance();
staticintmoney=0;
staticinti;
synchronizedpublicvoidrun(String name){
if(name=="1") save();
else get();
try{
wait();
}catch(Exception e){
e.printStackTrace();
}
}
publicvoid save(){
money+=100;
System.out.println("父亲存进去后剩余的钱" +formatter.format(money));
notify();
}
publicvoid get(){
money-=90;
System.out.println(" 儿子取出去剩余的钱" +formatter.format(money));
notify();
}
}