资源简介
模拟实现多线程处理银行的实时转账交易,代码完整,可以完美运行~

代码片段和文件信息
package task12_23.UpgradeTransferAccount;
/**
* Created by QXY on 2018/12/14.
*/
public class Account {
private String id;
private float balance;
private int transanctionNum=0;
private boolean available=true;
public String getId() {
return id;
}
public float getBalance() {
return balance;
}
public int getTransanctionNum() {
return transanctionNum;
}
Account(String idfloat balance){
this.id = id;
this.balance = balance;
}
public synchronized void checkavaialbe(){
while (!available){
// System.out.println(this.getId()+“ do not prepare well!***“+Thread.currentThread().getName()+“:Please wait~“);
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// System.out.println(Thread.currentThread().getName()+“:I get the account:“+this.getId());
this.available = false;
}
public synchronized boolean checkavaialbe(int locknum){
if(locknum ==0) {
while (!available) {
// System.out.println(this.getId() + “ do not prepare well!***“ + Thread.currentThread().getName() + “:Please wait~“);
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// System.out.println(Thread.currentThread().getName() + “:I get the account:“ + this.getId());
this.available = false;
return true;
}else {
if(!available) {
// System.out.println(Thread.currentThread().getName() + “ failed to lock the account:“ + this.getId() + “:I will quit~“);
return false;
}else {
// System.out.println(Thread.currentThread().getName() + “:I get the account:“ + this.getId());
this.available = false;
return true;
}
}
}
public synchronized void balanceadd(float amount)
{
this.balance += amount;
}
public synchronized boolean balancesub(float amount)
{
if(amount > this.balance)
return false;
this.balance -= amount;
return true;
}
public synchronized void setAvailable(){
available=true;
// System.out.println(Thread.currentThread().getName()+“:I‘m over~return the account:“+this.getId());
notifyAll();
}
public synchronized void transanctionNumAdd()
{
this.transanctionNum ++;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2733 2018-12-15 11:09 UpgradeTransferAccount\Account.java
文件 2873 2018-12-15 11:30 UpgradeTransferAccount\MainBank.java
文件 341 2018-12-14 23:30 UpgradeTransferAccount\Transaction.java
文件 3647799 2018-12-15 11:25 UpgradeTransferAccount\Transaction_record.txt
文件 2885 2018-12-15 11:21 UpgradeTransferAccount\TransferThread.java
文件 864 2018-12-15 11:24 UpgradeTransferAccount\utils.java
文件 15068 2018-12-04 16:07 UpgradeTransferAccount\多线程作业.docx
目录 0 2018-12-15 11:43 UpgradeTransferAccount\
相关资源
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
- 操作系统作业 (pv,作业管理,等5个
评论
共有 条评论