4月18日,TestCommunicate,每日20行。
来源:互联网 发布:无限极 树 mysql 编辑:程序博客网 时间:2024/06/08 15:05
class Account{ volatile private int value; volatile private boolean isMoney = false; synchronized void put(int i){ if(isMoney){ try{wait();} catch(Exception e){} } value = value + i; System.out.println("存入" + i + " 账上金额为:" + value); isMoney = true; notify(); } synchronized int get(int i){ if(!isMoney){ try{wait();} catch(Exception e){} } if(value > i) value = value - i; else{ i = value; value = 0; } System.out.println("取走" + i + " 账上金额为:" + value); isMoney = false; notify(); return i; }}class Save implements Runnable{ private Account a1; public Save(Account a1){ this.a1 = a1; } public void run(){ while(true){ a1.put(100); } }}class Fetch implements Runnable{ private Account a1; public Fetch(Account a1){ this.a1 = a1; } public void run(){ while(true){ a1.get(100); } }}public class TestCommunicate { public static void main(String[] args) { Account a1 = new Account(); new Thread(new Save(a1)).start(); new Thread(new Fetch(a1)).start(); }}
0 0
- 4月18日,TestCommunicate,每日20行。
- 4月17日,TestCommunicate,每日20行。
- 4月19日,TestCommunicate,每日20行。
- 6月4日,每日20行。
- 3月18日,CardLayoutDemo,每日20行。
- 4月20日,TestVector,每日20行。
- 4月4日,Decode,每日20行。
- 3月4日,simple_window,每日20行。
- 4月1日,StringEqualTest,每日20行。
- 4月2日,StringEqualTest1,每日20行。
- 4月3日,CharCode,每日20行。
- 4月5日,StringBufferPass,每日20行。
- 4月6日,StringBufferModify,每日20行。
- 4月7日,RemoveHZ,每日20行。
- 4月8日,DemogetProperties,每日20行。
- 4月9日,GetCurrentTime,每日20行。
- 4月10日,MyThread,每日20行。
- 4月11日,MyThread,每日20行。
- 后缀表达式(逆波兰表达式)
- AOP实现之相关概念与准备工作(一)
- Day2学习记录
- 深入理解 RCU 实现
- 设计模式实例与介绍
- 4月18日,TestCommunicate,每日20行。
- 是什么阻止了人工智能的步伐
- 文章标题
- 最近觉得Android Studio的黑色主题简直充满了工业美感
- SourceInsight集成圈复杂度检测工具
- 安卓动画总结
- HDU 1078 FatMouse and Cheese(记忆化搜索 Or DP)
- 利用事件委托提升性能
- as自动导入包名