银行取款程序 线程
2016-11-02 19:42
148 查看
public class Account01 {
public int balance;
}
}
第2个类 线程类
public class Method01 extends Thread {
}
第3个类 实现类
public class Test01 {
// Object o1 = new Object();
// Object o2 = new Object();
//
// ThreadA a = new ThreadA(o1,o2);
// ThreadB b = new ThreadB(o1,o2);
//
// a.start();
// b.start();
public int balance;
public Account01(int balance) { this.balance = balance; } public void qu(int money){ synchronized (this) {//对象锁 if(balance >= money){ System.out.println(Thread.currentThread().getName()+"当前余额为:"+balance); System.out.println(Thread.currentThread().getName()+"取款:"+money); balance-=money; System.out.println(Thread.currentThread().getName()+"取款后余额为:"+balance); } }
}
}
第2个类 线程类
public class Method01 extends Thread {
public Account01 account; public int money; public Method01(Account01 account,int money) { this.account = account; this.money = money; } @Override public void run() { account.qu(money); }
}
第3个类 实现类
public class Test01 {
public static void main(String[] args) { Account01 xm = new Account01(1000); Thread wx = new Method01(xm,100); wx.setName("微信"); Thread qq = new Method01(xm,100); qq.setName("QQ钱包"); Thread zfb = new Method01(xm,100); zfb.setName("支付宝"); wx.start(); qq.start(); zfb.start();
// Object o1 = new Object();
// Object o2 = new Object();
//
// ThreadA a = new ThreadA(o1,o2);
// ThreadB b = new ThreadB(o1,o2);
//
// a.start();
// b.start();
} }
相关文章推荐
- C语言实现的简单银行存取款程序 请输入如下数字命令
- Java线程之银行存取款
- Java--银行账户存取款线程设计1(交互线程)
- Java--银行存取款线程设计2(线程互斥)
- 程序 进程 线程
- 如何让程序自动管理线程
- ZSChatServer线程设计模型---客户端测试程序
- 使用线程,防止当前程序被阻塞
- 端口线程扫描程序(附源码BCB5)(1.0)
- 网上支付-用于与银行SOCKET通信的程序
- 向Web Service进军--Axis Tomcat模拟一个银行存取款服务
- C#线程:只要任何一个线程在运行,程序就不退出?!
- 各大银行借记卡取款手续费比较表
- Linux线程(3): 线程清理处理程序
- 程序通过创建线程实现删除自身
- 银行帐目管理程序
- 银行异地存取款收费比较(转)
- 从银行ATM机取款失败说起
- 银行本、异地,本、跨行存取款收费比较
- 有线程的程序会内存不足