public DepositMoneyThread(String thrName,Account account,double depositMoney)
{
super(thrName);
this.account = account;
this.depositMoney = depositMoney;
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int i = 0;i<10;i++)
account.deposit(depositMoney);;
}
}
复制代码
//DrawMoneyThread.java代码
package com.wayne.practice;
//定义取钱的线程
public class DrawMoneyThread extends Thread {
private Account account;
private double drawMoney;
public DrawMoneyThread(){}
public DrawMoneyThread(String thrName,Account account,double drawMoney)
{
super(thrName);
this.account = account;
this.drawMoney = drawMoney;
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int i = 0;i<10;i++)
account.draw(drawMoney);
}
}
复制代码
//AccountAppk.java代码
package com.wayne.practice;
public class AccountApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
Account acct = new Account("123456",0);
new DrawMoneyThread("取款者", acct, 800).start();
new DepositMoneyThread("存款者甲", acct, 800).start();
new DepositMoneyThread("存款者乙", acct, 800).start();
new DepositMoneyThread("存款者丙", acct, 800).start();
}