account_zhangzhen.java

来自「java的团队合作代码」· Java 代码 · 共 26 行

JAVA
26
字号
package com.jk.thread;

public class Account_zhangzhen {
	private double balance;
	
	public synchronized void withdraw (double price){
		while(this.balance<price){
			try {
				wait();
			    } catch (InterruptedException e) {
				
			    	e.printStackTrace();
			    }
			}
			this.balance -= price;
			System.out.println("Girl consume "+ price + " and balance has "+balance);
		}
		public synchronized void deposit(double earn){
			notifyAll();
			this.balance += earn;
			System.out.println("Boy earn " + earn + " and balance has " + balance);
		}
		

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?