account_yanggx.java

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

JAVA
23
字号
package com.jk.thread;

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

⌨️ 快捷键说明

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